Re: #ifdef

From: Dave Thompson (david.thompson1_at_worldnet.att.net)
Date: 09/23/04


Date: Thu, 23 Sep 2004 05:07:40 GMT

On Fri, 17 Sep 2004 10:12:39 -0000, Benjamin Ketcham
<bketcham@drizzle.com> wrote:

> Hash <a@b.com> wrote:
> > I have a small doubt,
> >
> > #ifdef _BSD
> >
> > When we use #ifdef preprocessor directive, the parameter which we pass
> > (in this case _BSD) is it defined by the user or is it defined somewhere
> > else?
> >
> > If the definition is somewhere where can i find the defnitions ?
>
> It may be defined by the user, or somewhere in a header file,
> or in other project files such as "Makefile". If the documentation
> is any good, it should tell you what symbols are defined, and where.
> Often, especially under Unix and its ilk, compiling software
> is a two step process: the first step, "configure", queries your
> system and creates one or more header files containing bunches of
> macro definitions representing what kind of system it is; the
> second step, "make", then [compiles using these definitions....]

> I would expect the symbol in question, "_BSD", to be defined
> automatically for you, if it is needed, either in a header file
> that is part of the software package, or in a system header file
> (often located under /usr/include on Unix), or as part of the
> "configure" process.
>
Agree so far, but especially for macros beginning with underscore
there is a third possibility -- they may be "builtin" to the compiler,
which may mean actually hardcoded or simply set somewhere in the
compiler installation. For the particularly flexible and common case
of gcc, this is in a file (usually?) in a place something like
/usr/lib/gcc-lib/$arch/$version/specs . Either way they should be
described in the compiler's documentation.

<snip>
> Many compilers have options to verbosely print out directories
> where they are searching for header files, and to display the
> C code after preprocessing but before compiling. These can help
> in tracking down issues with preprocessor symbols.
>
This won't help for builtins however. gcc does have an option -dM to
dump out macros at the end of compilation -- which if you compile a
(perhaps dummy) program that doesn't (significantly) change the
builtins and system settings, will show you what you've got.

- David.Thompson1 at worldnet.att.net



Relevant Pages

  • Re: #ifdef
    ... It may be defined by the user, or somewhere in a header file, ... out of a larger context such as the OS source code ... C code after preprocessing but before compiling. ... in tracking down issues with preprocessor symbols. ...
    (comp.lang.c)
  • Re: metadata operation failed (8013110E) : Database file is corrupt and may not be usable.
    ... This is an established project that has been compiling for several ... I can only add two more members to my ... tried adding an additional header file with no result. ... >slightly different metadata in two modules for the same type. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Converting from VS.net 2003 to VS.net 2005
    ... Visula studio 2003 as the editor and everything was compiling, ... Visual Studio 2005 instead of Visual studio 2003. ... We have included the afx.h before the afxwin.h in our source code ... As a fix we tried to make a seperate header file afxdlldef.h which said ...
    (microsoft.public.dotnet.languages.vc)
  • Problem in compiling a VC++ Studio Project on VC++.Net Plateform.
    ... There is no build problem on VC++ Studio 6.0 Platform. ... when I'm compiling it on VC++.Net 2003 Platform, ... Obviously I can't modify the header file by prefixing typename at those ...
    (microsoft.public.vc.language)
  • Re: PC Lint vs. splint
    ... // Some GNU macros return a value from bracketed expressions. ... // Global typedefs might not all be used ... For example, I have a header file that defines typedefs for S8, U8, ...
    (comp.arch.embedded)