[comp.unix.wizards] Concatenation with cpp.

Rminnich@UDEL.EDU (05/06/87)

   If you want to concatenate and you do not want to be 
portable, then 
#define cat(x,y)	x/* */y
works on many BSD systems. It will not work on SCO Xenix at all
and it sounds like it fails on SYS V too. It fails on SCO Xenix 
because they defined their own, improved cpp (called p0)
which of course does things differently. I just got bit 
by this in a big way on a piece of imported software. 
Our solution was adding the extra process. 

   It does not seem a good idea to use comments as an infix
concatenate operator, which is really what the above is. If
you really need the concatenate, and you do not want an 
extra process, then get GNU cpp. It supports concatenate
pretty nicely. It also uses alloca, which i understand 
is a very portable function :-) (which is why we do not 
use it on Xenix). If you want a copy 
please let me know.
ron (rminnich@udel.edu)

gwyn@brl-smoke.UUCP (05/06/87)

In article <7257@brl-adm.ARPA> Rminnich@UDEL.EDU writes:
>It also uses alloca, which i understand 
>is a very portable function :-) (which is why we do not 
>use it on Xenix).

Some time ago, I posted a mostly portable version of alloca().
Contact me if you really need a copy.
	- Gwyn@BRL.MIL

guy@gorodish.UUCP (05/07/87)

>    If you want to concatenate and you do not want to be 
> portable, then 
> #define cat(x,y)	x/* */y
> works on many BSD systems. It will not work on SCO Xenix at all
> and it sounds like it fails on SYS V too.

It doesn't sound like it fails on System V at all, if you read the
articles posted on this subject.  In fact I just tried it on a 3B2
running S5R3.0, and it worked just fine.

In case anybody didn't hear that, I'll repeat it again; IT WORKED
JUST FINE ON SYSTEM V.

However, the reason why it worked just fine on System V is that
System V Release 3.0 as released by AT&T for the 3B2 uses the Reiser
preprocessor, as do most BSD systems, and for that matter most System
III, System V, and V7 systems.  There is no guarantee that it will
work on other systems.  One possibility is to do as Arthur Olson
suggested and use "#ifdef __STDC__" to select whether the ANSI C
technique is to be used or the Reiser preprocessor technique is to be
used.

This works fine if you have an implementation that conforms to the
(draft!) ANSI C standard or that uses the Reiser preprocessor or
another preprocessor that works in that fashion, but it doesn't help
if you have one that doesn't support the ANSI C ## operator and
doesn't work like the Reiser preprocessor.  If that's the case,
you're on your own.