> -----Original Message----- > From: Martin Sebor [mailto:[EMAIL PROTECTED] On Behalf Of Martin Sebor > Sent: Wednesday, April 16, 2008 12:33 PM > To: [email protected] > Subject: Re: Another style question > ... > > As with every other convention, we're not 100% consistent, only > about 90% by my count.
Strictly speaking though, the #ifdef and #ifndef directives are redundant; i.e. `#ifdef foo` and `#if defined foo` are exactly the same but only the latter form permits compound expressions (e.g. `#if defined foo || defined bar`). > Btw., a more flexible way to code these workarounds would have been > to code it like so: > > #if !_RWSTD_NO_MEMBER_TEMPLATES > // correct code > #else > // workaround > #endif > > This way, each config macro could be #defined on the command line > to 0 or 1 to toggle either branch (e.g., for testing and debugging). > That's not possible with the #ifndef approach. >From a natural language perspective, I've always found the double negatives (e.g. `#ifndef _RWSTD_NO_FOO) a bit irritating but that's just me. > > Incidentally, speaking of #ifdefs, the other convention is to > add a comment after the #else and #endif directives mentioning > the name of the macro(s) used in the conditional (or some such > text) to help see which which branch is active. So according > to this convention the code above would look like so: > > #ifndef _RWSTD_NO_MEMBER_TEMPLATES > // correct code > #else // ifdef (_RWSTD_NO_MEMBER_TEMPLATES) > // workaround > #endif // _RWSTD_NO_MEMBER_TEMPLATES Yep. I use this convention myself though I find applying it unilaterally can be overkill in certain circumstances (e.g. when there's lots of non-nested #if-#else blocks consisting of only 5 lines each) but I do it anyway for consistency. Brad.
