Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: #if foo vs #if defined(foo) Message-ID: <3026@utcsri.UUCP> Date: Fri, 27-Jun-86 11:56:15 EDT Article-I.D.: utcsri.3026 Posted: Fri Jun 27 11:56:15 1986 Date-Received: Fri, 27-Jun-86 12:03:25 EDT References: <1586@brl-smoke.ARPA> <379@twitch.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 37 Keywords: Sys 5.2 Summary: In article <379@twitch.UUCP> grt@twitch.UUCP ( G.R.Tomasevich) writes: >Our compiler does not need a defined(), or at least I did not try whether >it is even accepted. The following example works fine: > >#if squat||foo >int yes; >#else >int no; >#endif >main() {} > >if the 'cc' command includes either '-Dsquat' or '-Dfoo', then 'yes' is >selected, else 'no' is selected. E.g.: 'cc -Dfoo -E c.c' >System: VAX-11/785 running UNIX 5.2 >-- This seems very wrong to me. If foo is defined (as 1), and squat isn't, shouldn't that come out as #if squat||1 which should be rejected by the cpp as containing a non-constant ? What if '#define squat 0' and '#define foo 0' ?? The expression becomes 0||0 which is false. This compiler here (4.2BSD) backs me up on the second point, but not on the first ( i.e. the given example works ). Apparently any symbol in a #if expression becomes '0'. What if squat or foo are defined as something other than a constant? This device cannot replace #if defined(a)|| defined(b) in general. -- "Shades of scorpions! Daedalus has vanished ..... Great Zeus, my ring!" ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg