Re: Who defines the platform specific macros eg LINUX VXWORKS etc



lovecreatesbeauty@xxxxxxxxx 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.
.



Relevant Pages

  • Re: what is the most suitable Linux platform for Programmers and software developers
    ... C, C++, Perl, Python, Lisp, and a bunch of other languages are supported ... There are FORTRAN compilers, but FORTRAN ... Look at the Linux ...
    (comp.os.linux.misc)
  • Re: g95 and Endianess
    ... Opteron with Linux that reads SGI binary data files ... be very problematic with other compilers, ... end type mytype ...
    (comp.lang.fortran)
  • Re: Thank you Microsoft!
    ... Actually, all of the .NET compilers have always been ... > Microsoft is an incredible organization. ... Linux was just cheaper. ... > the speed of your competitivenes. ...
    (microsoft.public.vsnet.general)
  • Re: Mixing C/C++ in the kernel
    ... Linux is written in C, and conspicuously does NOT support C++. ... to run inside the kernel, including templates, exceptions, RTTI, function ... different compilers, I'd say, so this is irrelevant. ... dont kill me, its just how i see things ...
    (comp.os.linux.development.system)
  • Re: Coding style article with interesting section on white space
    ... > Linux on Intel x86 at ... > compilers can be much larger, but that has less bearing on portability ... generation on Windows vs Linux (which _should_ pretty obviously be ... and code generator will be essentially unchanged across platforms, ...
    (comp.lang.python)