Is this correct action for the c compiler/preprocessor ??

J Q Johnson jqj at cornell.UUCP
Thu Oct 31 21:14:15 AEST 1985


Most versions of pcc ignore stringness (``"'') when looking for tokens 
for macro replacement.  Thus
	#define foo(a)	"This string contains a"
expands the call ``foo(X)'' to
	"This string contains X"

K&R are silent on the lexical issues involved, so this cannot be considered
incorrect.  However, some compilers, notably Tartan C, behave differently,
and expand the above example without substituting the ``a''.

A related issue is handling of comments in the preprocessor.  cpp permits
	#define makesym(a)	foo/**/a
which expands ``makesym(X)'' to ``fooX'' (unless, of course, -C is specified
in which case the comment is retained).  Other compilers might legitimately
strip the comments before parsing the macro definition, and thus might not
see the ``a'' in the definition as a separate token to be substituted, or
might substitute white space for the /**/, resulting in an expansion to 
``foo X''.



More information about the Comp.unix.wizards mailing list