Re: what will be the value of #define



On 2 Mar, 13:22, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxx> wrote:
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.

(Just in case it's a trick question): Impossible to tell,
based on the information provided.

(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.

To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
....
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.

.



Relevant Pages

  • Re: what will be the value of #define
    ... #ifndef SYSTEM_H ... defined as an object-like macro whose replacement list is empty. ... convention for ensuring that multiple inclusions of header files ... define the macro (as an empty macro) and do the other declarations, ...
    (comp.lang.c)
  • Re: what will be the value of #define
    ... #ifndef SYSTEM_H ... defined as an object-like macro whose replacement list is empty. ... To explain a little more for "raghu" - the approach is a standard ... convention for ensuring that multiple inclusions of header files ...
    (comp.lang.c)
  • Re: what will be the value of #define
    ... #ifndef SYSTEM_H ... defined as an object-like macro whose replacement list is empty. ... convention for ensuring that multiple inclusions of header files ... But there's no reason to care what it expands to, ...
    (comp.lang.c)
  • Re: what will be the value of #define
    ... convention for ensuring that multiple inclusions of header files ... #ifndef FRED_H ... then the first inclusion will have the macro "FRED_H" undefined, ...
    (comp.lang.c)
  • Re: [Clax86list] using common macros in NASM and C
    ... Not seeing any value in discussing the definition of a macro, ... generates a sequence of more detailed language statements." ... :with most of the Windows header files and try to create a NASM ... However, I have converted portions ...
    (comp.lang.asm.x86)