Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cuae2!ihnp4!alberta!sask!zaphod!billj From: billj@zaphod.UUCP Newsgroups: comp.lang.c,comp.bugs.4bsd Subject: Re: C preprocessor question Message-ID: <1180@zaphod.UUCP> Date: Fri, 13-Feb-87 15:09:15 EST Article-I.D.: zaphod.1180 Posted: Fri Feb 13 15:09:15 1987 Date-Received: Fri, 20-Feb-87 22:28:00 EST References: <818@wjvax.wjvax.UUCP> <12300@sun.uucp> Reply-To: billj@zaphod.UUCP (Bill Jones) Organization: Develcon Electronics, Saskatoon SK Canada Lines: 99 Keywords: preprocessor, UNIX, BSD, cpp Summary: cpp patch Xref: watmath comp.lang.c:1094 comp.bugs.4bsd:186 In article <818@wjvax.wjvax.UUCP> brett@wjvax.UUCP (Brett Galloway) writes: >...fails to compile on my system (4.2BSD): > >#define GROUP(group,subgroup) (((group) << 8) | (subgroup)) >#if GROUP(0,0) >#endif > >The #if chokes for some reason. A couple of other writers (jtr485@umich and pedz@bobkat) argue respectively that this shouldn't work, since the of a #if is very restricted; or that it should, as should everything including sizeof. Well, it depends on your cpp. Since V7, the #if should work with all non-assignment operators, including comma, but *not* sizeof since that's only determinable by the compiler proper, as are casts and enums. K&R section 12.3 did a hand wave on this one. In article <12300@sun.uucp> guy@sun.UUCP (Guy Harris) writes: >I don't know whether the Reiser preprocessor's >reluctance to expand "function-like" macro calls here is caused by >conceptual problems with doing that or implementation problems. I think I do. The Reiser cpp is getting its fancy scanner pointers mixed up after performing the substitution. As Tom Stockfish pointed out, the problem vanishes if you run cpp past the presubstituted form instead. The sloscan() set by ppcontrol() when it starts interpreting the contents of the #if line is being reset to fasscan() during the macro substitution, and cotoken() then blazes past all the substitued '(' characters. The following patch to the parameter substitution code in subst() stops that. Beware that the copy of cpp we have here is a decidedly non-vanilla version, and your line numbers will vary. -- Bill Jones, Develcon Electronics, 856 51 St E, Saskatoon S7K 5C7 Canada uucp: ...ihnp4!sask!zaphod!billj phone: (306) 931-1504 RCS file: RCS/cpp.c,v retrieving revision 1.2 diff -c -r1.2 cpp.c *** /tmp/,RCSt1001409 Fri Feb 13 13:07:00 1987 --- cpp.c Fri Feb 13 12:06:35 1987 *************** *** 2566,2571 { register char *ca, *vp; int params; char *actual[MAXFRM]; /* actual[n-1] is text of nth actual */ char acttxt[MAXBUF]; /* space for actuals */ --- 2575,2581 ----- { register char *ca, *vp; int params; + int wasfast = 0; char *actual[MAXFRM]; /* actual[n-1] is text of nth actual */ char acttxt[MAXBUF]; /* space for actuals */ *************** *** 2595,2601 ca = acttxt; pa = actual; if (params > 1) params--; ! sloscan(); /* * no expansion during search for actuals --- 2605,2614 ----- ca = acttxt; pa = actual; if (params > 1) params--; ! if (!isslo) { ! sloscan(); ! wasfast++; ! } /* * no expansion during search for actuals *************** *** 2728,2734 vp--; } skip--; ! fasscan(); } else if (inif) { --- 2741,2747 ----- vp--; } skip--; ! if (wasfast) fasscan(); } else if (inif) { -- Bill Jones, Develcon Electronics, 856 51 St E, Saskatoon S7K 5C7 Canada uucp: ...ihnp4!sask!zaphod!billj phone: (306) 931-1504