Preprocessor question (is gcc standard)?

Jonathan I. Kamens jik at athena.mit.edu
Thu Feb 28 02:51:00 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 ...
|> 		}

  I believe that GCC is correctly obeying the ANSI C standard here, although
it's hard to be sure.

  K&Rv2 says that an invocation of a macro with arguments must be the name of
the macro, followed by optional white space, followed by '('.  It doesn't say
that the '(' is allowed to be part of another macro that has been expanded.

  My guess is that the preprocessor is allowed to conclude as soon as it sees
a character that is not '(' after the name of the macro, that this isn't a
macro invocation.  If it couldn't do that, then every time macro substitution
happened, the preprocessor would have to check if the first non-whitespace
character of the substituted text was '(', and if so, go back and check if the
word before the '(' was the name of a macro with arguments.

  The relevant paragraph from K&Rv2 is the second paragraph on page 230.  You
should get yourself a copy :-).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.lang.c mailing list