Preprocessor question (is gcc standard)?

Doug Gwyn gwyn at smoke.brl.mil
Thu Feb 28 07:28:51 AEST 1991


In article <7654 at jhunix.HCF.JHU.EDU> barrett at jhunix.HCF.JHU.EDU (Dan Barrett) writes:
>	GCC's preprocessor doesn't like this code:
>		#include <ctype.h>
>		#define ARGS		(x)
>		main()
>		{
>			...	isalpha ARGS ...
>		}
>The linker complains that _isalpha is not known.  According to H&S and K&R,
>you are allowed whitespace between the name of a macro and its argument list
>in the invocation.

Yes, but the preprocessing token after the identifier in the function-like
macro invocation must be a left parenthesis, not another identifier.  At
the point that "ARGS" has just been macro-replaced, "isalpha" has been
left in the dust, and will not be rescanned to attach the newly-appeared
left parenthesis to it.

>	GCC's documentation says that a macro invocation that is not
>followed by a left parenthesis (ignoring whitespace) is not considered a
>macro invocation.  That explains why GCC doesn't like the above program.
>But is this the standard way an ANSI preprocessor should work?  I can see
>advantages and disadvantages to this behavior.

If the identifier corresponds to a previously-defined object-like macro,
it would be macro-replaced.  In this case, however, the definition is for
a function-like macro, which is supposed to be processed as I described
above.

There IS an error in the implementation, however -- the standard C
library is required (for a conforming hosted implementation) to provide
a definition for the isalpha() function.  It may (and probably does)
also provide a macro definition for isalpha() in <ctype.h>, but the
function is also required, to support applications that choose not to
use the macro definition.



More information about the Comp.lang.c mailing list