Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!think!ames!sdcsvax!ucbvax!decvax!minow From: minow@decvax.UUCP (Martin Minow) Newsgroups: comp.lang.c Subject: #if inside #define -- easy to do, but is it a good idea? Message-ID: <157@decvax.UUCP> Date: Fri, 25-Sep-87 21:11:49 EDT Article-I.D.: decvax.157 Posted: Fri Sep 25 21:11:49 1987 Date-Received: Sun, 27-Sep-87 07:06:55 EDT Reply-To: minow@decvax.UUCP (Martin Minow) Organization: Digital Eq. Corp. - Merrimack NH. Lines: 28 From time immemorial, C has forbidden # control lines inside a macro definition. When a collegue begged for this capability, I discovered it was trivial to add it to Decus CPP (which was posted to Usenet mod.sources about 2-3 years ago). It might be used as follows: #define set_bit(bit) \ #if debug \ printf("setting %04x\n", bit), \ #endif \ (device_register = (bit)) Decus CPP compiles macros by replacing formal parameters with the appropriate actual parameter and "pushing" the entire string back on the input file reader. The only change I had to make was to recognize the string "\ " during macro compilation and "expand" it as "". (Of course, the program is now non-transportable.) While the process may be more difficult for a tokenizing pre-processor, it shouldn't be too hard to implement. I'm sure it's too late in the review cycle to put this into the Standard (and it does violate the formal model), but it might be worth thinking of for the future. Or, did I forget something obvious? Martin Minow decvax!minow