Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!rutgers!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: cpp macro expansion Message-ID: <16909@sun.uucp> Date: Fri, 17-Apr-87 12:34:51 EST Article-I.D.: sun.16909 Posted: Fri Apr 17 12:34:51 1987 Date-Received: Sun, 19-Apr-87 12:09:06 EST References: <2857@linus.UUCP> Sender: news@sun.uucp Reply-To: guy@sun.UUCP (Guy Harris) Organization: Sun Microsystems, Mountain View Lines: 51 Keywords: cpp, #define, macro >#define MACRO(first,last) (\ >first\ >_\ >last) > >Which is the correct expansion, or is it left to the cpp implementors? The ANSI C standard indicates that backslash-newline should be completely stripped from source code fairly early in the translation process. This means that inserting blanks is incorrect; however, it also indicates that substituting for "first" and "last" is incorrect, because this macro definition should be treated identically to #define MACRO(first,last) (first_last) >Is there a problem with the (our?) Sun version 3.2 cpp? There is a problem with the System V "cpp", from which the 3.2 "cpp" is derived. There is a technique more likely to work on various versions of UNIX: #define MACRO(first,last) (first/**/_/**/last) However, *this* is not guaranteed to work on all C implementations, either. Also note that *neither* technique will work with the version of the preprocessor used in many UNIX C implementations if you call the macro as MACRO(foo, bar) since the blank in front of "bar" is considered part of the argument. Both of these facts argue against widespread use of this technique, since it isn't guaranteed to work and since it breaks if you make changes to the source code that one would think safe. >What (if anything) does the new standard say about this? It says you should write the macro like: #define MACRO(first,last) (first##_##last) which will cause the "first", the "_", and the "last" to be glued together into one token. It also says (see the "debug" macro in the example on pages 80 and 81 of the October 1, 1986 draft) that blanks in the argument list should not be considered part of the argument. Of course, this is a draft standard, and is subject to change.