Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site mcnc.UUCP
Path: utzoo!watmath!clyde!floyd!harpo!decvax!mcnc!ge
From: ge@mcnc.UUCP (George Entenman)
Newsgroups: net.lang.c
Subject: cpp bug/feature
Message-ID: <1948@mcnc.UUCP>
Date: Wed, 8-Feb-84 08:39:55 EST
Article-I.D.: mcnc.1948
Posted: Wed Feb  8 08:39:55 1984
Date-Received: Fri, 10-Feb-84 06:26:06 EST
Organization: Microelectronics Ctr. of NC; RTP, NC
Lines: 44

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.