For many embedded C developers the most predominate and questionable feature of C++ is the class. The concern is that classes are complex and therefore will introduce code bloat and increase runtimes in systems where timing is critical. Those concerns implicate C++ as not suitable for embedded systems. I’ll bravely assert up front that these concerns are unfounded.
When [Bjarne Stroustrup] created C++ he built it upon C to continue that language’s heritage of performance. Additionally, he added features in a way that if you don’t use them, you don’t pay for them.
Continue reading “Code Craft – Embedding C++: Classes”
My article on Fortran, This is Not Your Father’s FORTRAN, brought back a lot of memories about the language. It also reminded me of other languages from my time at college and shortly thereafter, say pre-1978.
At that time there were the three original languages – FORTRAN, LISP, and COBOL. These originals are still used although none make the lists of popular languages. I never did any COBOL but did some work with Pascal, Forth, and SNOBOL which are from that era. Of those, SNOBOL quickly faded but the others are still around. SNOBOL was a text processing language that basically lost out to AWK, PERL, and regular expressions. Given how cryptic regular expressions are it’s amazing another language from that time, APL – A Programming Language, didn’t survive. APL was referred to as a ‘write only language’ because it was often easier to simply rewrite a piece of code than to debug it.
Another language deserving mention is Algol, if only because Pascal is a descendant, along with many modern languages. Algol was always more popular outside the US, probably because everyone there stuck with FORTRAN.
Back then certain books held iconic status, much like [McCracken’s] black FORTRAN IV. In the early 70s, mentioning [Nicolas Wirth] or the yellow book brought to mind Pascal. Similarly, [Griswold, (R. E.)] was SNOBOL and a green book. For some reason, [Griswold’s] two co-authors never were mentioned, unlike the later duo of [Kernighan] & [Ritchie] with their white “The C Programming Language”. Seeing that book years later on an Italian coworker’s bookshelf translated to Italian gave my mind a minor boggling. Join me for a walk down the memory lane that got our programming world to where it is today.
Continue reading “No Pascal, not a SNOBOL’s chance. Go Forth!”
As we work on projects we’re frequently upgrading our tools. That basic soldering iron gives way to one with temperature control. The introductory 3D printer yields to one faster and more capable. One reason for this is we don’t really understand the restrictions of the introductory level tools. Sometimes we realize this directly when the tool fails in a task. Other times we see another hacker using a better tool and realize we must have one!.
The same occurs with software tools. The Arduino IDE is a nice tool for starting out. It is easy to use which is great if you have never previously written software. The libraries and the way it ties nicely into the hardware ecosystem is a boon.
When you start on larger projects, say you upgrade to a Due or Teensy for more code or memory space, the Arduino IDE can hamper your productivity. Moving beyond these limitations requires a new, better tool.
Where do we find a better tool? To begin, recognize, as [Elliot] points out that There is no Arduino “Language”, we’re actually programming in C or C++. We chose which language through the extension on the file, ‘c’ for C and ‘cpp’ for C++. An Arduino support library may be written in C or C++ depending on the developer’s preference. It’s all mix ‘n match.
Potentially any environment that supports C/C++ can replace the Arduino IDE. Unfortunately, this is not easy to do, at least for inexperienced developers, because it means setting up the language tool chain and tools for uploading to the board. A developer with that much experience might eschew an integrated development environment altogether, going directly to using makefiles as [Joshua] describes in Arduino Development; There’s a Makefile for That.
The reality is the Arduino IDE is not much more than a text editor with the ability to invoke the tools needed to compile and download the code to the Arduino. A professional IDE not only handles those details but provides additional capabilities that make the software development process easier.
Continue reading “Code Craft: Using Eclipse for Arduino Development”
I learned to program FORTRAN IV in the spring of 1968 while working as an engineering technician in water resources. One of the engineers knew of my interest in computers and asked if I would like to learn FORTRAN. He needed to calculate the biological oxygen demand in streams but didn’t have any interest in programming. I jumped at the chance.
This was the days of big iron when the term computer meant a room full of heavily air-conditioned equipment. The State University of New York at Buffalo had an IBM 704 but they soon upgraded to a CDC 6400. To help pay for it they were inviting people to attend a seminar on FORTRAN so they could use the system. My job was with a small State of NY office and getting approval for me to attend was surprisingly easy.
Off I went for 6 weeks of training on one night a week. I still have my black “A Guide to Fortran IV Programming” by [Daniel McCracken]. For years, this was the FORTRAN bible, commonly referred to as just “McCracken”.
The programming went well and somewhere out there is a very old paper with a reference to the results it generated about the Chadakoin River flowing through Jamestown, NY.
This is FORTRAN’s strength – scientific calculations. It’s name says it: FORmula TRANslation.
Origins and FORTRAN IV
[John W. Backus] suggested to IBM a language to replace assembly language. Development began in 1953 for the IBM 704 and the project reached fruition in 1957. Not only was it the first general purpose high-level language, just beating out COBOL and LISP, but its compiler optimized the code since it needed to compete head-on with assembly language. It was the C compiler of its day in that regard.
That was not the only reason it attained success. Reducing the number of punched cards needed for a program by a factor of 20 over assembly helped considerably.
In those days, you needed to use a key punch to create a deck of punch cards. To be really good you had to know how to create a programming card that would let you skip through the fields on a FORTRAN card, or how to edit a card by duplicating it and holding one of the cards in place while you typed in new characters. Because of my fascination with computers I’d taken a key punching and automation machines class in high school so I was all set.
Continue reading “This Is Not Your Father’s FORTRAN”
[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 versions 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++.
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”
[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”