C++ Turns 30 – Looking Forward to the Future

[Bjarne Stroustrup] introduced C++ to the world on Monday 14th October 1985 at the ACM annual conference on “The Range of Computing”. On its 30th anniversary [Bjarne] reviewed the history, his experience, and his thoughts on the future of the language in an interview. Also on that day the first edition of his book, “The C++ Programming Language” was released. It’s now available in a 4th edition. The title differed only in the “++” from the classic C book by [Kernighan] and [Ritchie] that graced the desktops of a multitude of C programmers.

The first versic++ bjarneons of C++ were compiled with CFront, a compiler that generated C code which was then compiled as normal. Around the 1990s, it’s unclear when, numerous native compilers became available, notably for PCs, which lead to explosive growth from 400,000 users to an estimated 4.4 million today.


One of the frustrations [Stroustrup] expresses is how C++ is viewed by developers,

… a problem that has plagued C++ forever: Poor teaching and poor understanding of C++ even among its practitioners. There has always been a tendency to describe C++ as some odd variant of something else.

Soon the standards committee is meeting to discuss C++17 in Hawaii. Fair winds and bright skies look to be in the future of C++.

Code Craft: When #define is Considered Harmful

An icon of Computer Science, [Edsger Dijkstra], published a letter in the Communications of the Association of Computer Machinery (ACM) which the editor gave the title “Go To Statement Considered Harmful“. A rousing debate ensued. A similar criticism of macros, i.e. #define, in C/C++ may not rise to that level but they have their own problems.

Macros are part of the preprocessor for the C/C++ languages which manipulates the source code before the actual translation to machine code. But there are risks when macros generate source code. [Bjarne Stroustrup] in creating C++ worked to reduce the need and usage of the preprocessor, especially the use of macros. In his book, The C++ Programming Language he writes,

Don’t use them if you don’t have to. Almost every macro demonstrates a flaw in the programming language, in the program, or in the programmer.

As C retrofitted capabilities of C++, it also reduced the need for macros, thus improving that language.

With the Arduino using the GNU GCC compilers for C and C++ I want to show new coders a couple of places where the preprocessor can cause trouble for the unwary. I’ll demonstrate how to use language features to achieve the same results more cleanly and safely. Of course, all of this applies equally when you use any of these languages on other systems.

We’re only going to be looking at macros in this article but if you want to read more the details about them or the preprocessor see the GNU GCC Manual section on the preprocessor.

Continue reading “Code Craft: When #define is Considered Harmful”

Code Craft: Subtle Interrupt Problems Stack Up

[Elliot Williams’] column, Embed with Elliot, just did a great series on interrupts. It came in three parts, illustrating the Good, the Bad, and the Ugly of using interrupts on embedded systems. More than a few memories floated by while reading it. Some pretty painful because debugging interrupt problems can be a nightmare.

One of the things I’ve learned to watch out for over the years is the subtlety of stack based languages, like C/C++, which can ensnare the unwary. This problem has to do with the corruption of arrays of values on a stack during interrupt handling. The fix for this problem points up another one often used by black hats to gain access to systems.

Continue reading “Code Craft: Subtle Interrupt Problems Stack Up”

Hack an Editor: Fonts for Programming

We’ve recently noticed two different fonts aimed at programmers, each with a different approach to editor customization. The first, Fira Code, transparently converts common programming digraphs into single characters. For example, <- becomes an arrow and != (or <>) becomes a proper not equal sign. The other font, Hack (can’t argue with the name), aims to make commonly confused characters distinct. For example, the zero glyph has a very distinct appearance from the letter O.

It is pretty easy to understand how Hack works, but Fira seems a mystery at first. Your C++ compiler expects <- not an arrow, right? Fonts support ligatures–sequences of two symbols that run together (like æ). Clever use of these ligatures means that the compiler still sees -> but the screen displays an arrow.

Continue reading “Hack an Editor: Fonts for Programming”

Amazon’s AI Escapes its Hardware Prison

It’s the 21st century, and we’re still a long way from the voice-controlled computers we were all promised in the 60s, 70s, 80s, and 90s. The state of voice interaction has improved, though, and Amazon’s release of the Alexa Skills Kit (ASK) is another sure step towards a future of computers that will pay attention to you. This allows any hardware to become Alexa, your personal voice assistant with the ability to do just about anything you command.

amazon_echoUp to this point, Alexa was locked away inside the Amazon Echo, the ‘smart’ cylinder that sits in your living room and does most of what you tell it to do. Since the Amazon Echo was released, we’ve seen the Echo and the Alexa SDK used for turning lights on and off, controlling a Nest thermostat, and other home automation tasks. It’s not Google Now, Microsoft’s Cortana, or Apple’s Siri that is behind all these builds; it’s Amazon’s Alexa that is bringing us into a world where Star Trek’s [Scotty] talking into an old Mac is seen as normal.

Right now, the Getting Started guide for the Alexa Skills Kit is focused more on web services than turning lights on and air conditioning off. Sample code for ASK is provided in JavaScript and Java, although we would expect 3rd party libraries for Python to start popping up any day now. If you want to run ASK on a Raspberry Pi or other small Linux computer, you’ll need a way to do voice capture; the Jasper project is currently the front-runner in this space.

We hope this changes the home automation game in a couple of different ways. First, the ASK processes everything in the cloud so very low power devices are now ready for some seriously cool voice interaction. Second, Amazon’s move to open up what you can do with the software backend means a community developing for the hardware could eventually exert pressure on Amazon to do things like making the system more open and transparent.

Already working on some hacks with the Echo or ASK? Send in a tip to your write-up and tells us about it in the comments below.

Talking, Foot-Pedal-Controlled Bench Probes for VirtualBench

Developing new products can be challenging during the debug and test phases, often you have your head down trying to probe the lead of some SOT23 transistor, and just when you get it, you scan your eyes up and find that your multimeter is measuring resistance and not voltage.

[Charles] had this issue compounded on his NI Virtual Instrument. It has an interface totally driven from a PC, which may or may not be in a convenient location to mouse around. Luckily NI just released an API for the 5 in one lab test station and [Charles] quickly whipped up a python wrapper which gives him ultimate control over the instrument.

Tying the script to a USB footpedal and adding some text-to-speech capabilities using google’s API [Charles] is easily able to switch from continuity to voltage to resistance and anything else he pleases with just the tap of a foot and listening to the measurements, making sure he never takes his eyes off the work which is risking a short.

Join us after the break for a quick video demonstration.

Continue reading “Talking, Foot-Pedal-Controlled Bench Probes for VirtualBench”

Flyfish FF32 Gets GUI

[CWroos] has written an impressive GUI for the Flyfish FF32. The Flyfish is a port expander of sorts, allowing the user access to a large array of I/O , analog inputs, SPI, I2C and a few other connectivity options over a USB connection. There is no driver as it uses a native HID driver in the operating system of the device it’s attached to. It’s not just tethered to a PC either. It works with Raspberry Pi, Beaglebone and several other SBCs.

program window

[CWroos]’s GUI makes it easier than ever to interact with the FF32. It has a script editor allowing you to run and edit scripts on the fly (pun intended). It appears he’s actually written his own basic like language for the scripting, which he goes into great detail on his site. There’s a blinky script example, and few more complex examples that will show you how to read temperature and control a servo.

There is also the ability to control the hardware directly allowing you to set pins, read firmware version, set the USB address and several other options. If you have an FF32 lying around, be sure to check out [CWroos]’s program and let us know how it works for you.