Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Preprocessor question (is gcc standard)? Message-ID: <15341@smoke.brl.mil> Date: 27 Feb 91 20:28:51 GMT References: <7654@jhunix.HCF.JHU.EDU> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 35 In article <7654@jhunix.HCF.JHU.EDU> barrett@jhunix.HCF.JHU.EDU (Dan Barrett) writes: > GCC's preprocessor doesn't like this code: > #include > #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 , but the function is also required, to support applications that choose not to use the macro definition.