C preprocessor question
billj at zaphod.UUCP
billj at zaphod.UUCP
Sat Feb 14 06:09:15 AEST 1987
In article <818 at wjvax.wjvax.UUCP> brett at 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 at umich and pedz at bobkat) argue
respectively that this shouldn't work, since the <expression> 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 at sun.uucp> guy at 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
More information about the Comp.lang.c
mailing list