On Mon, 27 Aug 2007, Andre Haupt wrote: > On Mon, Aug 27, 2007 at 09:47:09AM -0400, Robert P. J. Day wrote: > > > > is there an understood standard for documenting conditional > > preprocessor directives so you can more easily follow the logic in > > lengthy code segments? > > > > consider: > > > > #ifdef SNAFU > > ... very long blah blah ... > > #else > > ... equally long woof woof ... > > #endif > > > > if you're perusing the code, and you hit the "#else" or "#endif", > > it's almost impossible to tell what they correspond to, particularly > > if they're mixed in with even more nested directives. so what's the > > best way to make this more readable? > > > > what about something like? > > > > #ifdef SNAFU > > ... > > #else /* !SNAFU */ > > ... > > #endif /* !SNAFU */ > > I would make that latter > #endif /* SNAFU */ > instead, because the #endif refers to the #ifdef and not to the #else > statement. i thought of that but imagine that you're perusing code and you remember that you'd already seen: #ifdef SNAFU sometime later, you run across: #endif /* SNAFU */ now you're not sure if that's a simple end to "SNAFU" or possibly the "#else" part that you missed during the perusal. i'll grant you that it looks a bit funny but, IMHO, it really does add more information content, and has less chance of fooling you. of course, none of the above works very well if the preprocessor directive is some ugly, multi-part conditional, but there's not much you can do about those anyway. > sounds reasonable. Some people seem to hate comments in preprocessor > directives though. there's already lots of them in the code already, so the precedent has already been set. :-) rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://crashcourse.ca ======================================================================== - To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html