Who defines the platform specific macros eg LINUX VXWORKS etc

L

lovecreatesbeauty

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 */
 
J

James Kuyper

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top