Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!o.gp.cs.cmu.edu!fs7.ece.cmu.edu!psc.edu!nydick From: nydick@psc.edu (Dan Nydick) Newsgroups: comp.std.c Subject: pragmas vs preprocessors Message-ID: <1991Jan10.153117.29024@fs7.ece.cmu.edu> Date: 10 Jan 91 15:31:17 GMT Sender: news@fs7.ece.cmu.edu (USENET News System) Reply-To: nydick@psc.edu (Dan Nydick) Organization: Pittsburgh Supercomputing Center Lines: 46 I have an application where I'd like to have a macro expand into a #pragma. I tried the following: ---- #define THISISAPRAGMA #pragma something main() { /* blah blah */ THISISAPRAGMA /* blah blah */ } ---- I could imagine several interpretations for this... 1) insert and recognize the pragma in "main". 2) complain about the # in the macro definition. 3) insert "#pragma something" in main, but don't recognize it as a pragma. 4) don't expand THISISAPRAGMA at all. A quick scan of the C standard says that the # is illegal in a "functionlike" definition, but didn't rule it out in an "objectlike" definition. Anyway, various compilers I've tried have resulted in 2, 3, and 4. I haven't found a compiler which does option 1. I am able to run the code through the preprocessor and then feed the output back into the compiler to get the effect of option 1 with one of my compilers. Should this work? Which option is correct? How would one define a macro which expands into a pragma? Or even, how could one write a conditional expression so the pragma only appears if certain symbols are defined (plain ifdefs around the pragma are not good enough since some non-ansi compilers will complain about #pragma even inside a "false" condition)? Is a #pragma supposed to be significant to the compiler or to the pre-processor? My current workaround is to conditionally include a file which contains the #pragma line. Thanks in advance. Dan Nydick, Pittsburgh Supercomputing Center nydick@psc.edu