Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: define kinda stuff Message-ID: <2584@utcsri.UUCP> Date: Fri, 18-Apr-86 13:49:03 EST Article-I.D.: utcsri.2584 Posted: Fri Apr 18 13:49:03 1986 Date-Received: Fri, 18-Apr-86 13:55:27 EST References: <2604@brl-smoke.ARPA> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 78 Summary: It can be done... In article <2604@brl-smoke.ARPA> see@NTA-VAX.ARPA (Stein-Erik Engbr}ten) writes: >The problem is to define '(-:' as '/*' (start of comment), and :-) '*/'. > >> Obviously the right way to do this is the following: >> >> #define cat(a,b) a/**/b >> #define (-: cat(/,*) >> #define :-) cat(*,/) > >The preprocessor doesn't allow '(-:' as a definition-name >(Berkeley 4.2/4.3). > >However, the program below doesn't do what it is supposed to either. >When the preprocessor has finished, you just get 'main() {'. > >-->#define cat(a,b) a/**/b >-->#define start_comm cat(/,*) >-->#define end_comm cat(*,/) >--> >-->main() >-->{ >--> start_comm This is a comment end_comm >--> cat(pri,ntf)("This is a nice one...\n"); >--> printf("Hello...\n"); >-->} True. > >When in a comment, no expansion is done! > >How do we then define something which is to end a comment? I would say >it is impossible, but is eager to hear of anybody who thinks otherwise. > >Stein-Erik Engbr}ten The following method is stolen from one of the winners of last years' obfuscated-C-code contest ( Col. G. L. Sicherman ): ------------------- funny.c ---------------- #define b * #define start_comm /b #define end_comm b/ main() { start_comm This is a comment end_comm printf("Hello...\n"); } -------- cc -E funny.c: -------------------- # 1 "funny.c" main() { /* This is a comment */ printf("Hello...\n"); } I guess it works because the pre-processor doesn't *know* it is in a comment. The '/*' doesn't appear until *after* the 'b' is expanded, and by then the pre-processor is past the '/', so the comment is not recognized. The following also works (and was used in Col Sicherman's winning entry): #define toggle_comment /b/ Of course, this method causes the pre-processor to pass your comments to the compiler proper. ( By the way, Col Sicherman won the 'worst abuse of the preprocessor' category ). -- "If you aren't making any mistakes, you aren't doing anything". ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg