[comp.sys.next] strange behavior of the C preprocessor

cnh5730@calvin.tamu.edu (Chuck Herrick) (10/13/90)

Does this appear to be a bug in the C preprocessor to you?

With 
	setenv cpp /lib/cpp
I ran the following script (extracted from Larry Walls' Configure
in patch2)

cat <<'EOT' >testcpp.c
#define ABC abc
#define XYZ xyz
ABC.XYZ
EOT
echo 'Maybe "'$cpp'" will work...'
$cpp <testcpp.c >testcpp.out 2>&1

inspection of testcpp.out revealed that the file
contained
	abc .xyz
and NOT 
	abc.xyz
Since Larry's script checks to see if 'abc.xyz' IS
contained, it promptly bombs out.
By the way, /lib/cpp is a link to /lib/cpp-16


-- 
	Chuck Herrick				cnh5730@calvin.tamu.edu

cnh5730@calvin.tamu.edu (Chuck Herrick) (10/13/90)

In article <9060@helios.TAMU.EDU) cnh5730@calvin.tamu.edu (Chuck Herrick) writes:
)Does this appear to be a bug in the C preprocessor to you?
)I ran the following script (extracted from Larry Walls' Configure
)in patch2)
)cat <<'EOT' )testcpp.c
)#define ABC abc
)#define XYZ xyz
)ABC.XYZ
)EOT
)echo 'Maybe "'$cpp'" will work...'
)$cpp <testcpp.c )testcpp.out 2)&1
)inspection of testcpp.out revealed that the file
)contained
)	abc .xyz
)and NOT 
)	abc.xyz

In addition, I ran the script on a Sun SPARC 1+ which has
version 1.37 of the GNU C compiler/preprocessor
(cccp and cpp) installed along with the
vanilla Sun Berkeley C compiler.
when I ran the Sun C preprocessor (/lib/cpp) I got
	abc.xyz
and when I ran GNU's cccp and cpp I got
	abc .xyz

Since Larry's patch2 requires a C preprocessor which does
not produce this bug in order to unwrap and configure patch2,
one wonders how one will install a patch onto the GNU 
C preprocessor.


-- 
	Chuck Herrick				cnh5730@calvin.tamu.edu

geoff@ITcorp.com (Geoff Kuenning) (10/15/90)

In article <9063@helios.TAMU.EDU> cnh5730@calvin.tamu.edu (Chuck
Herrick) writes:

> Since Larry's patch2 requires a C preprocessor which does
> not produce this bug in order to unwrap and configure patch2,
> one wonders how one will install a patch onto the GNU 
> C preprocessor.

This is an artifact of GCC which Larry knows about.  Newer versions of
Configure use a slightly different regular expression which will
handle the inserted blank space (which is legal under the ANSI spec).
Meanwhile, the easy solution is to just modify the regular expression
in Configure by hand so that it handles blanks.
-- 
	Geoff Kuenning   geoff@ITcorp.com   uunet!desint!geoff

moose@svc.portal.com (10/16/90)

In article <9060@helios.TAMU.EDU> cnh5730@calvin.tamu.edu (Chuck Herrick) writes:
>Does this appear to be a bug in the C preprocessor to you?

Yes, but it is NOT a bug.


>#define ABC abc
>#define XYZ xyz
>ABC.XYZ

>inspection of testcpp.out revealed that the file
>contained
>	abc .xyz
>and NOT 
>	abc.xyz


That is correct.  That is ANSI not traditional preprocessing.  
Check out the ## token pasting.
-- 
Michael Rutman				|	moose@svc.portal.com
Cubist					|	makes me a NeXT programmer
Software Ventures			|	That's in Berkeley
smile, you're on standard disclaimer	|	<fill in with cute saying>

pbiron@weber.ucsd.edu (Paul Biron) (10/16/90)

In article <9063@helios.TAMU.EDU>, cnh5730@calvin.tamu.edu (Chuck
Herrick) writes:
|> In article <9060@helios.TAMU.EDU) cnh5730@calvin.tamu.edu (Chuck
Herrick) writes:
|> )Does this appear to be a bug in the C preprocessor to you?
|> )I ran the following script (extracted from Larry Walls' Configure
|> )in patch2)
|> )cat <<'EOT' )testcpp.c
|> )#define ABC abc
|> )#define XYZ xyz
|> )ABC.XYZ
|> )EOT
|> )echo 'Maybe "'$cpp'" will work...'
|> )$cpp <testcpp.c )testcpp.out 2)&1
|> )inspection of testcpp.out revealed that the file
|> )contained
|> )	abc .xyz
|> )and NOT 
|> )	abc.xyz
|> 
|> In addition, I ran the script on a Sun SPARC 1+ which has
|> version 1.37 of the GNU C compiler/preprocessor
|> (cccp and cpp) installed along with the
|> vanilla Sun Berkeley C compiler.
|> when I ran the Sun C preprocessor (/lib/cpp) I got
 
|> -- 
|> 	Chuck Herrick				cnh5730@calvin.tamu.edu

I posted something simular to this a while back, because I had
the same problem (actually I reported it as a bug to NeXT and
GNU).  The reply I received from RMS was that the behavior of
gcc (and hence cc on the NeXT) was the "proper" behavior and that
nothing was going to change.  The fact that I could produce what *I*
thought was the"proper" behavior on an HP (HP-UX 7.0), Sun Sparc
(SunOS 4.01), a VAX (BSD 4.3 tahoe), I was a little disappointed in
RMS's responce.  [Note that none of these C compilers are ANSI
compliant, except for HP's with the -Aa switch]

So, I posted to comp.lang.c to see what the concensus was there.
There answer turned out to be that ANSI compilant preprocessors
*ARE REQUIRED* to add the additional space around these tokens.
IOW, the Configure script form patch will not run with *ANY*
ANSI C.  Therefore, the "bug" is with patch, and *NOT* gcc (which
is an ANSI compliant compiler). [BTW, when I used the -Aa switch
on HP's 7.0 compiler, Configure failed]

I sent the whole conversation onto Larry Wall, and he said that in
the next distribution of patch, the problem will be fixed.

Paul Biron      pbiron@ucsd.edu        (619) 534-5758
Central University Library, Mail Code C-075-R
Social Sciences DataBase Project
University of California, San Diego, La Jolla, Ca. 92093