jbf@ccieng5.UUCP (Jens Bernhard Fiederer) (03/22/84)
We would like to define a macro that includes conditional compilation, i.e., is of the form #define MACRO(.....) \ ......\ #if .....\ .....\ #else\ .....\ #endif ...... ,,,,, Our pre-processor expands the macro, leaving the #if's. Is this a bug? Is there a way to force a second pass of the preprocessor? If there is, how do we force the #if, #else, and #endif to the beginning of the lines? Can Shirley find happiness in the arms of a Siberian dancing bear? Pleadingly Yours, Azhrarn and Rick -- Reachable as ....allegra![rayssd,rlgvax]!ccieng5!jbf Or just address to 'native of the night' and trust in the forces of evil.
gwyn@brl-vgr.ARPA (Doug Gwyn ) (03/25/84)
CPP is not a general macro processor. I don't think it can do what you are trying to make it do. Consider using "m4" for real macros.
dan@haddock.UUCP (03/26/84)
#R:ccieng5:-30100:haddock:12400005:000:1125 haddock!dan Mar 24 18:15:00 1984 It can't be done. Not easily, anyway. The only reason it doesn't work is that after the macro is expanded, there's no newline before the # to signal the preprocessor that this is another control to process. You could modify the preprocessor so that the sequence \<newline>, instead of being completely dropped, turns into a <newline> in the macro definition (I know, I did it once). But I don't recommend it. Instead, you might try writing the macro with an embedded special character like '@' where newlines ought to appear, running the source through cpp alone to expand the definitions, and then running the result through 'tr' to convert those characters to newlines. Then run the result through the preprocessor again (and the rest of the compiler). Example: #define foo(x) \ @#if x \ @some code \ @#endif might be the source. The commands would be something like cc -P foo.c; tr '@' '\012' <foo.i >x.c; cc x.c I used -P because it will preserve line number information. Nonetheless, the line numbers in diagnostics (and debuggers) should be regarded with healthy skepticism the first few times you do this.