#defining insanity



  • #ifndef __MWERKS__
    #define myCONSOLE_H <console.h>
    #include myCONSOLE_H
    #endif

    Note that this is the only place in the codebase that the myCONSOLE_H pre-processor define is used.


  • I'm guessing they wanted to be able to override the include file at compile time, but I can't think of a single reason why it would be useful.  Going back to the WTF at hand, in order to override the #include, one would not only have to define myCONSOLE_H to something (including the <>'s), but define MWERKS as well.  No wonder it's the only place in the code this is used.



  • skippy, the WTF is the use of the myCONSOLE_H define.  Just the fact that the #include was inside of an #ifndef is enough to override the inclusion at compile time.

    Looks like somebody who didn't understand preprocessor commands was trying to edit an include guard.



  • [quote user="RevEng"]

    skippy, the WTF is the use of the myCONSOLE_H define.  Just the fact that the #include was inside of an #ifndef is enough to override the inclusion at compile time.

    Looks like somebody who didn't understand preprocessor commands was trying to edit an include guard.

    [/quote]

     

    Oh, I totally agree with you about the main WTF.  I was speaking more along the lines of passing define options to gcc/cl/whatever compiler it is.  For all we know, this file might have been the main include file for a cross-platform project, where myCONSOLE_H was used all over the place, but over time all of that code was removed/rewritten and this was all that was left and no one thought to remove it.  Legacy code tends to do that... a lot.

     



  • [quote user="skippy"]Going back to the WTF at hand, in order to override the #include, one would not only have to define myCONSOLE_H to something (including the <>'s), but define __MWERKS__ as well.[/quote]

    The Metrowerks compiler will do the latter for you :) 



  • This may not even be a WTF at all.

    I haven't used the MetroWerks IDE in a long time but from what I remember, it's meant to develop lots of stuff for embedded applications. It automatically defines __MWERKS__, and my guess is that the IDE overrides myCONSOLE_H during build depending on which embedded platform it was building for (if that platform had a platform specific console).  I've seen this kind of thing before and my guess is it does it for other includes as well.

    -the hermit

     



  • [quote user="The Hermit"]

    This may not even be a WTF at all.

    I haven't used the
    MetroWerks IDE in a long time but from what I remember, it's meant to
    develop lots of stuff for embedded applications. It automatically
    defines MWERKS, and my guess is that the IDE overrides myCONSOLE_H
    during build depending on which embedded platform it was building for
    (if that platform had a platform specific console).  I've seen
    this kind of thing before and my guess is it does it for other includes
    as well.

    [/quote]

    Before it was purchased by Freescale, MetroWerks CodeWarrior was [i]the[/i] C/C++ development environment for the Macintosh, and this is Mac/Windows/DOS/*nix crossplatform code.  Part of the MetroWerks Standard Library provides a full POSIX-like environment on MacOS 9 and earlier, including standard in/standard out.  On some non-MetroWerks compilers (note that it's "#if[b]n[/b]def MWERKS"), you need to include a file called "console.h" and a separate library to get an emulated terminal and make I/O to stdin, stdout, and stderr do something sensible.

    Of course, The Real WTF is that they're specifying "not CodeWarrior" when they should be enumerating the compilers that [i]do[/i] need console.h.


Log in to reply