views:

97

answers:

1

WinNT.h has the following lines in it, in the VS2008 SP1 install:

#define BitTest _bittest
#define BitTestAndComplement _bittestandcomplement
#define BitTestAndSet _bittestandset
#define BitTestAndReset _bittestandreset
#define InterlockedBitTestAndSet _interlockedbittestandset
#define InterlockedBitTestAndReset _interlockedbittestandreset

I have a number of templates that are based on BitTest<>()

Does anyone know of a simple way to disable these #defines?

Oftentimes MS does provide a #define XXX symbol which, if defined, will disable some offending portion of their header - e.g. NOMINMAX.

I have been unable to find such a solution to the above problem.

If you share frustration with Microsoft's many dubious choices, the read on. If not, stop here. ;)

Editorializing:

  • Why couldn't Microsoft just use the _bittest itself???
  • Or why couldn't they use BITTEST like every knows you should - always use all-caps for macros!
  • Microsoft is still #defining things in 2010?! WTF?
+1  A: 

Unfortunately, Microsoft believes it's OK to make their APIs use macros for names since they do it for 95% or more of their APIs to make them work 'transparently' for ANSI vs. Unicode APIs.

It doesn't look like they've provided a clean way to prevent the macro from being defined. I think you're stuck with choosing from several bad options, including:

  • #undef BitTest yourself
  • modify the winnt.h header
  • segregate your code that uses Windows APIs directly into modules that aren't dependent on your BitTest<> template

I'm sure there are other options - I'm just not sure sure which one is the least distasteful.

Michael Burr
Personally, I don't mind the Ansi/Unicode #defines. So long as they give me a clean and clear way to disable unwanted #defines, I'm a happy camper. In this case, I've not found such a mechanism. It does seem goofy to me that they're still creating such anachronisms. It was one thing to do this in 1990, or even in 2000. Its quite another to still be using such poor programming habits in 2010, no?
Mordachai
I don't disagree (except maybe a little about the Ansi/Unicode defines - I wish there were a better way to handle that, though I honestly can't say I know of a better alternative).
Michael Burr
For the record, I'm going with #undef BitTest in my "BitTest.h" header. Its ugly, its stupid, and it annoys the hellouttame, but I see no alternative to this at the moment (short of renaming my template and every occurrence of it - in 20+ projects). MS can really bite sometimes. If someone has a better alternative, I'd be most interested. ;)
Mordachai