#defines with parameters

Chris Torek chris at mimsy.UUCP
Sun Nov 27 08:48:39 AEST 1988


>>In article <1988Nov22.170953.24489 at utzoo.uucp> henry at utzoo.uucp
>>(Henry Spencer) writes:
>>>Definitions of parameterized macros ... have always been required to
>>>have the "(" immediately following the identifier.  The May draft
>>>standard requires that in the invocation, the "(" must be "the next
>>>preprocessor token", which basically means that white space there is okay.

Translation:

	#define	IDENT(a)	(a)

		IDENT   ( foo   )

is perfectly legal and produces `foo';

	#define	ANAME	(bar)

		ANAME(a,b)

produces `(bar)(a, b)' (syntactically a function call).

>In article <264 at aber-cs.UUCP> pcg at cs.aber.ac.uk (Piercarlo Grandi) writes:
[much not worth quoting]

In article <8982 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>It would be nice if you checked what X3J11 had done before venturing an
>opinion.

Indeed.  However:

>If you're referring to the adoption of "value preserving" rules for type
>conversion, that is clearly a logical improvement over "sign preserving"
>rules, leading to surprising behavior less often, and turned out upon
>investigation to not break a significant amount of code already written
>according to sign-preserving rules.  Both variations were found in
>existing practice before X3J11 had to make a choice, and they chose the
>patently better set of rules.

All of this is true save the `clearly ... improvement', `surprising
...  less often', and `patently better' (which are all opinions).  The
problem with value-preserving rules is that predicting the type of of
an expression requires knowing something that cannot be known
portably:  it requires knowing whether the expanded (rvalue) type of an
lvalue actually contains more bits than the lvalue's type.  That is,
the type of the expansion of an `unsigned short' might be `unsigned
int' or `int', and there is no way to tell which.  (It is, however,
true that casting to whichever type is desired will patch things up and
eliminate any difference between the two methods.)

>[parentheses in macro def/ref:]  Henry was mistaken about this.

While he did not use dpANS phrasing, he did get the details right.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list