about compile option -D

Posted on 2002-03-13
Last Modified: 2013-12-06

When using "cc" to compile a C program, -DXXXX can be specified as a compile option. Here, "XXXX" may be a macro defined by myself, or a macro defined by Solaris, such like "_LP64". Is there any way to know what macros Solaris provides? And how about such of HP-UX?

Question by:fancyqin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 51

Expert Comment

ID: 6864611
use cc -v  to display what the compiler sets by default

When you say "to know what macros Solaris provides?", I assume you want to know which macros are possible.
Short answer: there is no way.
Long answer: this is the wrong question, somehow.
Solaris does not "provide macros". The macros are used and defined in the source files. macros can be (nearly) any string.
To find out which are used by the OS (Solaris, HP-UX, etc.), do something like:
     find /usr/include -type f -name \*.h -exec grep define {} \;|sort -u
be prepared for a huge output.
LVL 40

Expert Comment

ID: 6866094
Well that depends on what you are trying to find out and what compiler is being used. There are a set of system & compiler predefinitions for all operating systems. On a Solaris system with a Workshop or Forte C compiler those predefinitions are shown in 'man cc'. If Gnu C is installed you'd get it's predefinitions by:

> touch foo.h
> cpp -dM foo.h

So far as I know the trick with cpp will work on any OS that includes cpp.

Expert Comment

ID: 6882053
U can u man cc inorder to find the predefined MACROS available for the compiler in that particular platform
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

ID: 6887967

Execute "man -M /opt/SUNWspro/man cc", got:
   Associates name with the specified token  as  if  by  a
   #define  preprocessing  directive.   If  no  =token  is
   specified, the token 1 is supplied.
               sparc (SPARC)
               i386 (Intel)

   The above are not predefined in -Xc mode.
   These predefinitions are valid in all modes:
            __`uname -s`_`uname -r`
            __sparc (SPARC)
            __i386 (Intel)
            __LITTLE ENDIAN (PowerPC)
            __ppc (PowerPC)
   The following is predefined in -Xa and -Xt modes only:
   The compiler also predefines the object-like macro
   to indicate the pragma will be recognized.

Those above are all predefined MACROS?

Accepted Solution

akohli earned 117 total points
ID: 6887994
I think Yes..But in order to test. DO small test on Your platfrom.Like


#ifdef _sun
printf("SUN is already defined \n");


Compile it without any complier flag and check..
LVL 40

Expert Comment

ID: 6888558
Yes, those are all of the publically defined values for Sun's compiler. There are, I believe, others that exist but they aren't intended for use by programs and may change from one compiler release to another. In general system pre-defined values will be prefixed with '__'. So if you are wanting to avoid a clash with a system definition don't use '__' as a prefix for a local definition.
LVL 21

Expert Comment

ID: 7833240
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by akohli

Please leave any comments here within the next 7 days


tfewster (I don't work here, I'm just an Expert :-)

Expert Comment

ID: 7908981
Finalized as proposed


Community Support Moderator
Experts Exchange

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question