Microsoft macros, please see Stroustrup

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.

Advertisements

Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: