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

Dick Dunn rcd at opus.UUCP
Mon Nov 4 18:27:49 AEST 1985


The question was whether the C preprocessor should substitute for an
occurrence of a macro formal within a string within the body of the
macro...
> >It also fails to work correctly on the C compiler supplied with Un*x
> >system V for the AT&T Un*x PC but it does work the opional LPI C
> >compiler; But don't ask me why?
>...
> It does not "fail to work correctly" -- that's how it works.  It
> allows you to say something like
> 
> 	# define	Pval(var)	printf("var = %d\n", var)
> 	...
> 	pvar(Count);
> 	pvar(Errors);
> ...
> Being able to insert literal text in strings is very useful.

The fact that a feature is "useful" is not sufficient argument that it is
correct.

Ken Arnold (>) continues with a discussion about what happened in the
standards committee--apparently they found it useful but didn't accept it.
Leaving aside what happened there, and leaving aside the usefulness of the
feature, the problem stems from the fact that the definition that most of
us use these days (K&R) says one thing:
	Text inside a string or a character constant is not subject to
	replacement.
...which is pretty explicit, but the compiler that a lot of us use
substitutes inside strings.  I would like to have an authoritative
definition and a correct compiler in accord with the definition.  Lacking
this, let's not throw too many stones; the compiler may not be wrong, but
it's not clearly right.

I'd like to know how the discrepancy came about--anyone care to fill me in
(by email, preferably).
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Never attribute to malice what can be adequately explained by stupidity.



More information about the Comp.lang.c mailing list