Posts Tagged ‘Stroustrup’

Microsoft macros, please see Stroustrup

June 4, 2011

This past week at work, I looked into why I could use a member variable called “interface” just fine in some source files but not others. Preprocessor output showed the name interface was being changed to “struct” in the files that had errors, and sometimes not where I defined the data structure that contained the interface field, but somewhere else later in the file. I eventually tracked down the culprit to objbase.h, a Microsoft supplied header file used by Direct3D 9 and maybe some other stuff. It has this wonderful gem:

#define interface  struct

No C or C++ developer should ever do that. There is no good or justifiable reason to name a macro something that, in many naming conventions, is a perfectly fine name to use for something other than a macro. Most naming conventions use all capital letters only for macro names in order to avoid such confusion.

Bjarne Stroustrup also sees this as a problem. He recommends avoiding macros whenever possible, and I can see why. This is easier to do in C++ with the help of such things as templates that are not in C, but adhering to a good naming convention can eliminate a lot of troubles when macros must be used.

In short, I find it inexcusable for any developer to do something like what I found in objbase.h. Whoever is responsible should be slapped. I can only hope that has already happened.


False Steps

The Space Race as it might have been

You Control The Action!

High Frontier

the space colony simulation game

Simple Climate

Straightforwardly explaining climate change, so you can read, react and then get on with your life.