www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/10/16:02:37

Date: Sat, 10 Feb 1996 14:54:45 -0600 (CST)
From: Aaron Ucko <UCKO AT VAX1 DOT ROCKHURST DOT EDU>
Subject: Re: defines for djgpp V1.x and V2
To: alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de
Cc: djgpp AT delorie DOT com
Message-id: <01I11VYKXNTY000106@VAX1.ROCKHURST.EDU>
Organization: Rockhurst College; Kansas City, MO
MIME-version: 1.0

>: >#if (DJGPP >= 2)
>: ^^^^^^^^^^^^^^^^^
>
>: But wouldn't that break if you try it with DJGPP V1? There, DJGPP isn't
>: defined at all by default.  So poor old cpp would have to find out if
>: "DJGPP" is larger or equal to "2".  Looking into the cpp manuals, I see
>: that for undefined DJGPP, it is treated as being zero, and that works. 
>: But there's at least one major multi-platform software package (gnuplot)
>: that uses a "-DDJGPP" to flag that DJGPP is the actual platform.  That
>: would mean cpp had to compare "" >= "2".  Looks like I have to return to
>: base and re-read K&R and the cpp docs to find out what cpp does with
>: such comparisons. 
>
>If seems like cpp treats undefined identifiers in #ifs as causing the
>condition to fail. If you write #if BLA > 1, then the #else part is
>processed (so the construct works as expected), if you do it the other way
>around #if BLA <= 1, it doesn't work.
>
>If a cpp symbol is defined on the commandline -DBLA, the implicit definition
>is #define BLA 1, so this works also, but it the symbol is defined in a header
>file as #define BLA or if the command argument is -DBLA=, it causes a parse
>error and the compilation fails.

Solution (borrowed from nethack, I seem to recall): #if DJGPP+0 >= 2.
This should work as long as DJGPP is not defined to something like a
string.

-- Aaron Ucko (ucko AT vax1 DOT rockhurst DOT edu; finger for PGP public key) | httyp!
"That's right," he said. "We're philosophers. We think, therefore we am."
-- Terry Pratchett, _Small Gods_ | Geek Code 3.1 [for explanation, finger 
 hayden AT mankato DOT msus DOT edu]: GCS/M/S/C d- s: a18 C++(+++)>++++ UL++>++++ P++ 
 L++>+++++ E- W(-) N++(+) o+ K- w--- O M@ V-(--) PS++(+++) PE- Y(+) PGP(+) t(+)
 !5 X-- R(-) tv-@ b++(+++) DI+ !D-- G++(+++) e->+++++(*) h!>+ r-(--)>+++ y?

- Raw text -


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