[comp.lang.c] #if inside #define -- easy to do, b

aglew@ccvaxa.UUCP (10/03/87)

>rbutterworth@orchid.waterloo.edu
>In article <29339@sun.uucp>, david@sun.uucp (David DiGiacomo) writes:
>> In article <157@decvax.UUCP> minow@decvax.UUCP (Martin Minow) writes:
>> >From time immemorial, C has forbidden # control lines inside a
>> >macro definition.
>> It would be a nice feature to have, but it's not really necessary for your
>> example
>
>OK, here's a real example where it would be useful
>(in fact I can't see any nice way of doing this without the ability):
>
>    #if !defined(compiler_A)
>    #if !defined(compiler_B)
>    #if !defined(compiler_C)
>    ^%$%^#^%$&^% syntax error since we don't know this compiler.
>
>    #else  /* compiler_C */
>    #   define ARGSUSED /*ARGSUSED*/
>    #endif /* compiler_C */
>
>    ...


Not the subject of this discussion (although I would like to have a real
macro language standard for cpp), but the construct above shows the importance
of (1) the #elif construct, and (2) a need for a standard abort-compilation
construct:

#if defined(compiler_A)
..
#elif defined(compiler_B)
..
#elif defined(compiler_C)
..
#else
#abort Don't know this compiler - can't define AGSUSED
#endif

I thibk it was Whitesmith's C that had the #abort construct, and
it was very useful.

meissner@dg-rtp.UUCP (Michael Meissner) (10/06/87)

In article <28700020@ccvaxa> aglew@ccvaxa.UUCP writes:
> 
> ... a need for a standard abort-compilation construct ...
> 
> I thibk it was Whitesmith's C that had the #abort construct, and
> it was very useful.
> 
And ANSI has defined #error to do this.

-- 
Michael Meissner, Data General.		Uucp: ...!mcnc!rti!xyzzy!meissner
					Arpa/Csnet:  meissner@dg-rtp.DG.COM

henry@utzoo.UUCP (Henry Spencer) (10/07/87)

> ... a need for a standard abort-compilation construct...

X3J11 has done this, there is a #error construct.  The Rationale observes:
"The directive #error has been introduced to provide an explicit mechanism
for forcing translation to fail under certain conditions. ... Traditionally
such failure has had to be forced by inserting text so ill-formed that the
translator gagged on it."
-- 
PS/2: Yesterday's hardware today.    |  Henry Spencer @ U of Toronto Zoology
OS/2: Yesterday's software tomorrow. | {allegra,ihnp4,decvax,utai}!utzoo!henry

gwyn@brl-smoke.ARPA (Doug Gwyn ) (10/10/87)

In article <8722@utzoo.UUCP> henry@utzoo.UUCP (Henry Spencer) writes:
>such failure has had to be forced by inserting text so ill-formed that the
>translator gagged on it."

My usual method is
	#include "*** ERROR -- whatever ***"