The most useless code ever

Found in an old programming assignment for 9th grade Intro to Computer Programming class:

#ifndef NULL
#define NULL NULL
#endif

Now, I’m hoping that I wrote that just to fuck with the teacher (which I did a LOT because she was mean and didn’t know jack about C, C++, or any language except MS-QBasic).

BTW, I confirmed that the GNU C/C++ preprocessor simply ignores those three lines.  I’m hoping any other sane preprocessor does, too.

Advertisements
  1. #1 by Random Blog org on December 20, 2009 - 9:08 PM

    why would they be used though?

    • #2 by Joshua on December 21, 2009 - 7:42 AM

      Do you mean, “Why would anyone ever put those three lines into production code?” That’s sort of the point – no sane person would (should) ever write such completely useless code.

      • #3 by Chadwick on December 21, 2009 - 10:20 AM

        Fortunately, you’re not sane.

  2. #4 by sheep, andrewd's coworker on December 22, 2009 - 4:44 PM

    Does it really just ignore those lines? I posed the question to StackOverflow:

    http://stackoverflow.com/questions/1949670/define-null-null

    • #5 by Chadwick on December 22, 2009 - 4:53 PM

      Hey Sheep. Long time no see. Merry Christmas and whatnot.

    • #6 by Joshua on December 22, 2009 - 5:29 PM

      Hmm… It seems you are correct – running the cpp command from within a gdb session allows me to see that the preprocessor does indeed check to see that NULL is actually defined prior to parsing the code.

    • #7 by Joshua on December 22, 2009 - 5:30 PM

      I stand corrected. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: