🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5228

Concatenating tokens that aren't parameters, in ANSI C

#5228
From: John Gilmore
Date: Tue, 26 Jul 1988 04:47
43 lines
2039 bytes
I'm still trying to get Unix to compile and run under an ANSI C compiler
(gcc).  The latest wierd problem comes from the Fortran I/O library, where
they define the number of significant digits in a float and then want
to define a constant containing 1e(that number).  Under pcc, they used:

#define LFD 6
#define LHIGH 1.0e+LFD

which expanded to

1.0e+6

which worked just fine.  This no longer works, since the preprocessor
works on "pp-tokens" one of which is a "pp-number" which includes all
of "1.0e+LFD" (once you've seen a digit, it includes letters and digits
and "e"s followed by signs until kingdom come).  It never sees "LFD" as
a separate token like the old one did.  I have tried various kludges to
make this work; the obvious:

#define LHIGH 1.0e+ ## LFD

fails because ## does not fully expand its arguments before concatenating
them; it only expands them if they are parameters to the macro (boo!).
I tried various more complex alternatives and NEVER got any of them to
work.  Some of this may be due to gcc-1.24 bugs; I expect that:

#define cat_a(a,b) a ## b
#define cat_b(a,b) a ## b
#define LHIGH cat_a(1.0e+,cat_b(LFD,))

should work, but it produces:

1.0e+cat_b(6 ,)  

a wierd result, probably due to misimplementation of the overly complex
ANSI C anti-self-calling rules.

If C had exponentiation, I could define LHIGH (10.**(LFD-1)) and hope
for constant folding, but there's no **.  Does anyone have any suggestions?
-- 
John Gilmore    {sun,pacbell,uunet,pyramid,amdahl}!hoptoad!gnu    gnu@toad.com
      "And if there's danger don't you try to overlook it,
       Because you knew the job was dangerous when you took it"
Technical Details
Message-ID: <4963@hoptoad.uucp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ucbvax!hoptoad!gnu

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ucbvax!hoptoad!gnu
From: gnu@hoptoad.uucp (John Gilmore)
Newsgroups: comp.std.c
Subject: Concatenating tokens that aren't parameters, in ANSI C
Message-ID: <4963@hoptoad.uucp>
Date: 26 Jul 88 04:47:05 GMT
Organization: Grasshopper Group in San Francisco
Lines: 42