#undef, #define

From: Christopher Benson-Manica (ataru_at_nospam.cyberspace.org)
Date: 03/30/04


Date: Mon, 29 Mar 2004 22:58:32 +0000 (UTC)


(assume for the purposes of this question that the implementation is
C89-compliant)

Let us say that the following lines exist in a certain header file:

#if !defined(BOOLEAN_T)
#define BOOLEAN_T
typedef unsigned short boolean;
#endif

And let us further say that the following line is found in another
header:

typedef unsigned char boolean;

Finally, suppose that the first header has already been preprocessed
by the time the line in the second header is reached. How does one
ensure that boolean is only defined once? I've tried

#undef boolean
#ifndef boolean
#ifndef BOOLEAN_T

and none of them seem to prevent boolean from being redefined by the
second header file and leading to fatal compile-time errors. Any
suggestions, besides cursing the name of he who wrote the first header
file?

(The players in this little drama are def.h, the company standard
header file, yuk yuk, and a standard header file for an updated
version of my implementation.)

-- 
Christopher Benson-Manica  | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org    | don't, I need to know.  Flames welcome.


Relevant Pages

  • Re: #undef, #define
    ... > Let us say that the following lines exist in a certain header file: ... > typedef unsigned short boolean; ... > #ifndef BOOLEAN_T ... > second header file and leading to fatal compile-time errors. ...
    (comp.lang.c)
  • Re: #undef, #define
    ... > Let us say that the following lines exist in a certain header file: ... thus leading to no definition of boolean. ... > #ifndef BOOLEAN_T ... > second header file and leading to fatal compile-time errors. ...
    (comp.lang.c)
  • Re: #undef, #define
    ... > by the time the line in the second header is reached. ... > ensure that boolean is only defined once? ... > second header file and leading to fatal compile-time errors. ... > header file, yuk yuk, and a standard header file for an updated ...
    (comp.lang.c)
  • Re: NULL pointer dereferencing - behaviour
    ... > something without having to reference what header file NULL is in), ... > just being a matter of personal style. ... > the standard header file soup. ...
    (comp.lang.cpp)
  • Re: Header questions
    ... standard header file being included twice. ... some compelling reason. ...
    (comp.lang.c)