Solved

about compile option -D

Posted on 2002-03-13
8
381 Views
Last Modified: 2013-12-06
Hello,

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?
Thanks.

sincerely,
fancyqin
0
Comment
Question by:fancyqin
8 Comments
 
LVL 51

Expert Comment

by:ahoffmann
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.
0
 
LVL 40

Expert Comment

by:jlevie
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.
0
 

Expert Comment

by:akohli
ID: 6882053
U can u man cc inorder to find the predefined MACROS available for the compiler in that particular platform
0
 

Author Comment

by:fancyqin
ID: 6887967
Hello,

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

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

Those above are all predefined MACROS?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Accepted Solution

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


main()
{

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

}

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

Expert Comment

by:jlevie
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.
0
 
LVL 20

Expert Comment

by:tfewster
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

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

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

Expert Comment

by:modulo
ID: 7908981
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
g++ pthread_init failure on AIX 10 68
pauing printer deamon in AIX 10 52
nodeip 9 68
Move nodes from one TSM to another. 3 51
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now