draft ANSI standard: major, quiet, unnoticed change
Gregory Smith
greg at utcsri.UUCP
Thu Dec 4 08:51:28 AEST 1986
>In article <1379 at hoptoad.uucp>, gnu at 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 at brl-sem.ARPA> ron at brl-sem.ARPA (Ron Natalie <ron>) 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...
More information about the Comp.lang.c
mailing list