Who defines the platform specific macros eg LINUX VXWORKS etc

Discussion in 'C Programming' started by lovecreatesbeauty@gmail.c0m, Oct 31, 2008.

  1. 0m

    0m Guest

    Are these macros defined in Makefile or by some environment which can
    detect the platform types?

    /* common code here */

    #ifdef LINUX

    /* other os spefic code */

    #elif defined VXWORKS

    /* other os spefic code */

    #elif defined MACOSX

    /* other os spefic code */

    #elif defined WIN32

    /* other os spefic code */

    #endif

    /* common code here */
    0m, Oct 31, 2008
    #1
    1. Advertising

  2. 0m

    James Kuyper Guest

    0m wrote:
    > Are these macros defined in Makefile or by some environment which can
    > detect the platform types?
    >
    > /* common code here */
    >
    > #ifdef LINUX
    >
    > /* other os spefic code */
    >
    > #elif defined VXWORKS
    >
    > /* other os spefic code */
    >
    > #elif defined MACOSX
    >
    > /* other os spefic code */
    >
    > #elif defined WIN32
    >
    > /* other os spefic code */
    >
    > #endif
    >
    > /* common code here */


    There is no one answer to that. They can be defined in user code. Most
    compilers provide some mechanism for pre-defining some identifiers
    before the code is processed. For instance, all of the compilers I use
    would accept a "-DLINUX" option which has the same effect as

    #define LINUX

    or a "-DLINUX=1' option which has the same effect as

    #define LINUX 1

    However, it often happens that make files will set these options as part
    of the build script for your program. POSIX make files (I'm not familiar
    with non-POSIX make files, if there are such things) allow you to define
    make variables, which are often used to store such options, and any such
    variable that is not explicitly set by the make file is implicitly
    filled in by using the value of an environment variable of the same
    name. Therefore, while the environment and the make file do not set
    these macros, they both typically play a role in getting them set.

    In short, there's no simple answer to your question. About the only
    possibility that does not exist is that a fully conforming C compiler
    would pre-define any of these macros itself. Those names all are from
    the name space reserved for users, so a conforming implementation can't
    predefine them.
    James Kuyper, Oct 31, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    444
    Thomas Matthews
    Feb 19, 2004
  2. Replies:
    80
    Views:
    2,331
    Stephen J. Bevan
    Nov 7, 2003
  3. Replies:
    1
    Views:
    415
    Marco Antoniotti
    Oct 7, 2003
  4. Replies:
    5
    Views:
    479
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    361
    Fredrik Lundh
    Aug 13, 2008
Loading...

Share This Page