ge@mcnc.UUCP (George Entenman) (02/08/84)
I believe that the following behavior of the C preprocessor should be considered to be a bug, or at least that it should be changed unless it serves some useful function. I wrote a file with the following five lines: # define LINE A, B, C, D # define LISTPARMS( i, j, k, l ) ( a = (i), b = (j), c = (k), d = (l) ) line LINE listparms LISTPARMS(A,B,C,D); listparms LISTPARMS( LINE ); In my opinion, BOTH calls to LISTPARMS should produce the same output. However, if you run this file through the C preprocessor (pipe it through /lib/cpp, for example) you will get the following output: line A, B, C, D listparms ( a = (A), b = (B), c = (C), d = (D) ); listparms ( a = ( A, B, C, D ), b = (), c = (), d = () ); The last line will also produce the error message: filename: lineno: LISTPARMS: argument mismatch The problem is that the proprocessor decides that listparms LISTPARMS( LINE ); has only one parameter BEFORE it expands the LINE macro. LINE expands as the string "A, B, C, D", which is then substituted into LISTPARMS as its first parameter. I believe that this is a bug and not a feature. Has anyone fixed this bug in cpp? If so, could you send me the changes? While I'm on the topic of cpp, I would like to second the recent suggestion made by Robert Berlinger that cpp be modified so that macros would be able to accept a variable number of arguments. George Entenman The Microelectronics Center of North Carolina ...decvax!mcnc!ge By the way, I used m4, which doesn't have this bug/feature, to write the macros that I needed.