JB Enterprises

JB Enterprises - Johan Bezem

Interim Management & Consulting

JB Enterprises - Blog


Programming in the C/C++ realm: Identifier names to avoid – or not?

The C family of languages has been around for a while, has evolved, grown, sprouted a few branches and now provides several paths for 'growth'. Starting out in the seventies, standardized in the eighties, C++ in the nineties, standardized even more recently, industry-standard variants available for embedded (C++), and new standardization efforts on the way. Wonderful!
Currently, just as many times before, I'm working on a project with fairly high safety requirements, programmed in C. Not C99, but C89 with a few compiler extensions for embedded programming. Not because C++ or at least C99 is not available, but because of the inertia of legacy code, and the experience level of the (otherwise highly skilled) developers. You don't turn a team of experts in C into a team of experts in C++ within a few weeks, and the project's goals take priority always.
A few weeks ago I was looking at a piece of code like this:

ui32 calculate_difference(ui32 old, ui32 new) { ... }

That gave me pause. Yes, it's perfectly OK for C89, even C99 will not complain. But do I really want to use a C++ keyword in my C code? If ever I get to move to C++, my code must break!
Having been a brief and passing guest at the C++ WG21 July 2009 meeting in Frankfurt, I started off on some research. (This list is just for illustration, not for completeness)

  • An interesting keyword from the old days has been forgotten since C89: entry
  • C89 introduced a new keyword void
  • AMD1 introduced some new semi-keywords: or_eq, and_eq. These are not keywords in the pure sense, but you might still want to avoid them as identifier names
  • C99 added at least one more: restrict
  • C++ adds a whole army of keywords: static_cast, template, class
  • The coming C/C++ standards will add several more: _Complex, _Imaginary

So I'm now trying to find out answers to the following question: What identifier names would I want to avoid in my code, considering the vast realm of C/C++ language variants and dialects? So I started off with the keywords of all standards; then I looked into the coming standards, then I looked at the might-be keywords, packaged as macros, like complex, imaginary, decimal64, etc. The list grew, I lost my overview, however slim it had been, and I didn't even start on the various (Standard!) libraries!
I'm now starting on a more structured approach. A quick tweet didn't get me any response. Many overviews on the net present parts, but nothing comprehensive as far as I've seen, so I guess I'll have to roll my own.
If you happen to know a source of information on this, please do let me know, preferrably by email. I'd be more than interested.
And whether you do or don't, you're welcome to come back here occasionally, as I'll be reporting my findings.

Happy coding!

November 23rd, 2009

Valid XHTML 1.0 Strict Valid CSS www.bezem.de: © 1999 – 2019 by Johan Bezem, all rights reserved.
This page was last updated on Tuesday, 2017-07-25 17:31.