ryan@cwruecmp.UUCP (Ryan McGuire) (04/09/86)
*** REPLACE THIS LINE WITH YOUR MESSAGE *** O.K. all you people out there who think you know everything, I got one for ya: Here's what I wanna do: #define (-: /* #define :-) */ Obviously I want to make (-: and :-) my comment delimiters. One problem, though, is that the compiler or preprocessor (or whatever it is that does it) interprets most of the above as a comment containing '\n#define :-)'. How do I get around this??? Here are the other things I tried (which didn't work). #define (-: \/* this didn't work because it put \/* in for every (-: #define (-: "/*" ditto but with a "/*" #define (-: '/*' ditto but with a '/*' #define (-: /\* ditto but with a /\* #define (- / this pair was rejected for a number of reasons: #define : * 1. It would mean I would have to make my smileys like this (- : 2. To make matters worse that got interpreted as / * (notice the space) instead of /*. 3. And lastly something like 5 / (-3 * a) would become 5 / /3 * a) . Of course I could do something along the lines of... %alias cc 'sed {sed commands} $1 | cc' ...or something like that, but I wanted to put something in an include files that I could send to all my friends to use; I don't want to make them all put a new alias in their .login files. If anyone could help me on this one, it would be greatly appreciated. One thing, however: before you mail me any suggestions try them to make SURE they work. Thanks Ryan McGuire
trent@cit-vax.Caltech.Edu (Ray Trent) (04/11/86)
[this space for rent] In article <1458@cwruecmp.UUCP> ryan@cwruecmp.UUCP (Ryan McGuire) writes: > Here's what I wanna do: > >#define (-: /* >#define :-) */ I don't know about your C compiler, but MY prepreocessor barfs at having a macro named "(-:", so I would imagine that even if you get /* to (not) expand correctly, this construct will not be portable. I quote from K&R: A compiler-control line of the form #define identifier token-string ...causes the preprocessor to...(Appendix A, ss 12.1) and: Appendix A.2.2: Identifiers An identifier is a sequence of letters and digits; the first character must be a letter.... -- ../ray\.. (trent@csvax.caltech.edu) "The above is someone else's opinion only at great coincidence"
argv@sri-spam.ARPA (AAAARRRRGGGGv) (04/11/86)
In article <1458@cwruecmp.UUCP> ryan@cwruecmp.UUCP (Ryan McGuire) writes: > Here's what I wanna do: > >#define (-: /* >#define :-) */ As we all know, this is not possible, however someone around here tried it and found a strange compiler error: "endif not found" Code was: #define \(-: "/*" #define :-\) "*/" (-: comment :-) main(){} Well, *I* thought it was a compiler error since there was no "if" for the preprocessor! Something a little more interesting, tho, is that the following code, submitted by someone learning C on the Sun: char foo[3][10] = { "one"; "two"; "three"; }; main() { printf("%s\n", foo[1]); } crashes the C compiler with a segmentation violation (sun only)! Oh, it recognizes the syntax error, but as soon as it tries to do something with the printf statement, it barfs with a seggie! Strange... dan (argv@sri-spam.arpa)
henry@utzoo.UUCP (Henry Spencer) (04/11/86)
> Here's what I wanna do: > > #define (-: /* > #define :-) */ > > Obviously I want to make (-: and :-) my comment delimiters. One problem, > though, is that the compiler or preprocessor (or whatever it is that does it) > interprets most of the above as a comment containing '\n#define :-)'. How > do I get around this??? ... You won't like the answer: you can't. Not portably, anyway. Comment processing is done before #define processing in most compilers. You might be able to find a compiler which would do what you want, but C compilers in general won't. The X3J11 drafts are quite explicit that comment stripping precedes #define processing, so the situation is not going to get better. To reiterate something that has been said before: the C preprocessor is not intended as a general-purpose macro processor. -- Support the International League For The Derision Of User-Friendliness! Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,decvax,pyramid}!utzoo!henry
rjk@mrstve.UUCP (Richard Kuhns) (04/15/86)
In article <1458@cwruecmp.UUCP> ryan@cwruecmp.UUCP (Ryan McGuire) writes: > > O.K. all you people out there who think you know everything, I got >one for ya: > > Here's what I wanna do: > >#define (-: /* >#define :-) */ > > Obviously I want to make (-: and :-) my comment delimiters. One problem, > [etc] > Thanks > Ryan McGuire I don't believe you can do it (portably, anyhow) with the C Preprocessor, but if you send your program thru m4 (macro preprocessor) first, you should be able to do it. -- Rich Kuhns {ihnp4, decvax, etc...}!pur-ee!pur-phy!mrstve!rjk
ken@rochester.ARPA (Ipse dixit) (04/18/86)
>I don't believe you can do it (portably, anyhow) with the C Preprocessor, >but if you send your program thru m4 (macro preprocessor) first, you should >be able to do it. Nope, unfortunately, m4 only substitutes for identifiers, i.e. letter{letter,digit}*. Ken -- UUCP: ..!{allegra,decvax,seismo}!rochester!ken ARPA: ken@rochester.arpa Snail: CS Dept., U. of Roch., NY 14627. Voice: Ken!
joel@gould9.UUCP (Joel West) (04/21/86)
why not just run your program through a script that says sed -e 's/(-:/\/*/' -e 's/:)/*\//' and then you needn't worry about it. -- Joel West (619) 457-9681 CACI, Inc. Federal, 3344 N. Torrey Pines Ct., La Jolla, CA 92037 {cbosgd, ihnp4, sdcsvax, ucla-cs} !gould9!joel {seismo!s3sun, hplabs!hp-sdd, sun!pyramid} !gould9!joel joel%gould9.uucp@NOSC.ARPA