delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/01/08/18:52:32

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Message-ID: <3FFDEB2F.F9560613@yahoo.com>
Date: Thu, 08 Jan 2004 18:43:43 -0500
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: stdbool.h and complex.h
References: <Pine DOT OSF DOT 4 DOT 58 DOT 0401071356580 DOT 26260 AT sirppi DOT helsinki DOT fi>
<3FFCF1F4 DOT B86AC9DA AT yahoo DOT com> <Pine DOT OSF DOT 4 DOT 58 DOT 0401081156010 DOT 23737 AT sirppi DOT helsinki DOT fi>
Reply-To: djgpp-workers AT delorie DOT com

Esa A E Peuha wrote:
> On Thu, 8 Jan 2004, CBFalconer wrote:
> 
> > > #ifndef __dj_stdbool__h_
> > > #define __dj_stdbool__h_
> > >
> > > #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
> > >   || !defined(__STRICT_ANSI__)
> > >
> > > #define bool _Bool
> > > #define true 1
> > > #define false 0
> > > #define __bool_true_false_are_defined 1
> > >
> > > #endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
> > >
> > > #endif /* !__dj_stdbool__h_ */
> >
> > I question whether it is necessary to have the __STDC_VERSION etc.
> > guard, or even desirable.
> 
> Yes, it is both.  If the user asks for strict ANSI C89, then our
> headers must not define anything not in that standard, even if any
> specific header (like this one) isn't in the standard.  Maybe we
> should add warnings like "#warn using stdbool.h while in strict
> ANSI C89 mode" (or even #error, since strict ANSI doesn't know
> about #warn).

On reconsideration I think you and Eli are right.  However I would
separate out the strict part.  The thing being guarded against is
the use of _Bool below C99, because it doesn't exist.  Strict C89
is already eliminated.  The #error could be a #else since below
C99 the header shouldn't exist either.

I routinely use the following header (which could use
improvement):

/* Standard defines of operators, usable on C90 up */
#ifndef stdops_h
   #define stdops_h
   #if defined(__STDC__) && (__STDC_VERSION__ >= 199901L)
      /* The following from C99 - must define for C90 */
      #include <stdbool.h>       /* define bool, true, false */
      #include <iso646.h>        /* define not, and, or, xor */
   #else
      #define false 0
      #define true  1
      typedef int   bool;
      #define not   !
      #define and   &&
      #define or    ||
      #define xor   ^
   #endif
#endif

which handles the things I want to use.

-- 
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019