CC bug test

Kee Hinckley nazgul at apollo.uucp
Thu Jan 31 01:51:03 AEST 1985


...

This applies mainly to BSD users, but everyone is free to try.

I've seen several pieces of code out there that say "#ifdef V4.2".
Nothing wrong with that, right?  WRONG.  The K&R state that macros
are identifiers, and identifiers DON'T have '.'s in them.  If they
did how would you do structure references?  I have been told that
in fact "V4.2" works only because the Berkeley compilers ignore the
".2".  If this is the case then two things are true.  The following
shell script is NOT going to do what you expected, and someone had
better come up with a better "#ifdef".  I rather hope that the latter
is done regardless of the former, since strict C compilers won't compile
a program that says "#ifdef V4.2".  Which makes it a bit of a pain for
those of us who port the torrents of stuff coming across the net.

Here goes.

main()
{

    printf("Currently compiling only");
#ifdef V4
    printf(" V4");
#endif
#ifdef V4.1
    printf(" V4.1");
#endif
#ifdef V4.2
    printf(" V4.2");
#endif
    printf(" lines.\n");

}

                                                    -Kee Hinckley
                                          ...decvax!wanginst!apollo!nazgul

P.S.  I don't think there are any syntax errors in the above program (other
      than the one in question), but I don't guarantee it since I can't
      compile it!



More information about the Comp.lang.c mailing list