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: comp.lang.c Subject: Re: draft ANSI standard: major, quiet, unnoticed change Message-ID: <3722@utcsri.UUCP> Date: Wed, 3-Dec-86 17:51:28 EST Article-I.D.: utcsri.3722 Posted: Wed Dec 3 17:51:28 1986 Date-Received: Wed, 3-Dec-86 18:43:43 EST References: <1379@hoptoad.uucp> <500@brl-sem.ARPA> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 66 Summary: >In article <1379@hoptoad.uucp>, gnu@hoptoad.uucp (John Gilmore) writes: >> #pdefine sun >> >> would cause #if sun or #if defined(sun) or #ifdef sun to be true, but >> would not replace occurrances of "sun" in program text. > In article <500@brl-sem.ARPA> ron@brl-sem.ARPA (Ron Natalie ) writes: >Of course, no one said it had to be a macro definition. You could >just say > int sun; >and the #if defined(sun) would also work. Of course, it takes up >a few bytes. Too bad the compiler won't allow me to declare voids. > Baloney, the preprocessor doesn't know that 'int sun' has been defined. I like John's idea; it is not really a 'kludge' as he says; in fact the concept of using string-substitution symbols to control conditional compilation is the kludge, and the #pdefine would cure this. How do you define these in the command line? possibility: cc ... -Pfoo -Dbar -Dlimit=200 is equivalent to #pdefine foo #define bar 1 #define limit 200 but I have always thought there should be an explicit mechanism for importing stuff from the command line: cc -Dfoo -Dbar -Dlimit=200 combined with #conditional foo #parameter bar #parameter limit in the source, would be equivalent to the above defines. the '-D' symbols ( and any predefined stuff, 'unix' etc) would be waiting in the wings, so to speak, until activated by the #parameter or #conditional. It would be an error if a #parameter were applied to a symbol that wasn't 'waiting in the wings' -- the advantage of this is obvious. If you had a system that would compile on a vax or sun, you would have to put "#conditional vax/#conditional sun" at the beginning. If you compiled it on a 'widget', the definition of 'widget' would not take effect, hopefully causing a compile error, and forcing the user to take note that changes may be required, and to add "#conditional widget" after making those changes. Conditional switches could be implemented painlessly: #conditional vax,sun,widget could cause an error if none of the symbols are 'waiting'. ( if only one symbol is listed, and is not waiting, nothing happens). If more than one of the symbols is waiting, the first in the list *only* would be activated. Thus the programmer would be certain that exactly one of vax,sun,widget is defined. The mechanism will not allow site-dependant or command line defines, except those anticipated by the programmer, to have any effect on the program. This is the main advantage. Of course this breaks existing code; but it may be fixed by adding #parameters, and #conditionals to the code. These parameters and conditionals should be documented in comments anyhow, of course. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...