Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!cmcl2!brl-adm!umd5!cvl!elsie!ado From: ado@elsie.UUCP Newsgroups: comp.lang.c Subject: Re: #if inside #define -- easy to do, but is it a good idea? Message-ID: <7510@elsie.UUCP> Date: Sat, 3-Oct-87 13:37:06 EDT Article-I.D.: elsie.7510 Posted: Sat Oct 3 13:37:06 1987 Date-Received: Sun, 4-Oct-87 02:44:58 EDT References: <157@decvax.UUCP> <29339@sun.uucp> <10898@orchid.waterloo.edu> Organization: NIH-LEC, Bethesda, MD Lines: 43 Summary: existing techniques < > > From time immemorial, C has forbidden # control lines inside a < > > macro definition. < ...here's a real example where it would be useful... < #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 */ < < #else /* compiler_B */ < # define ARGSUSED #argsused < #endif /* compiler_B */ < < #else /* compiler_A */ < # define ARGSUSED #pragma argsused < #endif /* compiler_A */ < < goes into a header file, and a program can simply use the manifest < ARGSUSED < in the appropriate places. Rather than allowing # directives in macros, it suffices to do macro substitution in directives (as is done by the 4.3BSD C compiler and by the System V Release 2 compiler, but not by the DECUS C preprocessor). The above code then becomes #ifdef compiler_A #define USEDARGS pragma argsused #elif compiler_B #define USEDARGS argsused #elif compiler_C #define USEDARGS /*ARGUSED*/ #else !Funky!Stuff! #endif and a program can simply use #USEDARGS in the appropriate places. -- ado@vax2.nlm.nih.gov ADO, VAX, and NIH are trademarks of Ampex and DEC.