Berkeley CSUA MOTD:Entry 26101
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2002/10/4-5 [Computer/SW/Languages/C_Cplusplus] UID:26101 Activity:insanely high
10/4    Which of the following #endif comment in C is better?
        (a) #ifdef FOO
              ... foo code ...
            #else
              .... non-foo code ...
            #endif /* FOO */
        (b) #ifdef FOO
              ... foo code ...
            #else
              ... non-foo code ...
            #endif /* !FOO */
        Thanks.
        \_ a actually makes sense.
           \_ to normal people, but I'm sure that some 1337 l1nux d00d5 will
              like (b) better. (Trust me, I've seen stranger)
              \_ Ah, the GNU way.
                         \_ please learn to spell, its GN00 not GNU.
                            - 1337_5P34Kd
        \_ The first one is better, since !FOO is usually used to match
           a ifndef FOO.
        \_ I don't get the joke.....
           \_ Me either.  Some sort of ultra nerd thing I guess.
              \_ It's not a joke.  I'm trying to figure out how to write my
                 code.  Thanks for the responses so far.
                 \_ Uhm... ok.  You realise its the same code and only the
                    final comment is different by a single character?  Neither
                    way is "better".  Comments are there to make sense of your
                    code for others.  I don't think you need that comment at
                    all unless you work with monkeys in which case it won't
                    matter anyway.  Good luck!
                    \_ Yes, only the final comment differs by a single
                       character.  I should've mentioned that the code between
                       the #if and #else and between the #else and #endif is
                       usually pretty long, about 100 lines or so.  So I want
                       to see which comment makes the code more clear to
                       others.
                       \_ Oh.  In that case I'd use the first one.
                          \_ Okay.  Thanks.
        \_ A.  the #endif goes with the #if, not with the #else.  Otherwise,
           it'd be #endelse.
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2004/5/28-29 [Computer/SW/Compilers] UID:30481 Activity:nil
5/28    I just found out that bison inserts these lines of code
                #ifndef __cplusplus
                #ifndef __STDC__
                #define const
                #endif
                #endif
	...
2004/1/21 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:11861 Activity:nil
1/20    Any candidates for the best way to prevent developers from #includeing
        a header file accidentally.  Aside from very loud comments to that
        effect, what is a good way to make the compiler complain?  I was
        thinking something like
        #ifndef MYLIB_I_REALLY_WANT_TO_USE_THE_PRIVATE_INTERFACE
          // best way to cause compiler pain goes here
	...
2001/8/21-22 [Computer/SW/Languages/C_Cplusplus] UID:22202 Activity:kinda low
8/21    What's the general rule for nesting C include files?  Say if FOO is
        defined in foo.h and bar.h uses FOO, should I makde bar.h #include
        foo.h, or should I let whatever .c files that use bar.h include foo.h?
        \_ use #ifdefs
        \_ As a general rule, if a file uses FOO, it should #include
           whatever file declares FOO.  If you also use #ifdefs (which
	...