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
rbj@icst-cmr (root) (04/10/86)
O.K. all you people out there who think you know everything, Those people who think they know everything are annoying to those of us who do. I got one for ya: Here's what I wanna do: #define (-: /* #define :-) */ Obviously I want to make (-: and :-) my comment delimiters. Obviously you need to read T.F. manual. What makes you think you can redefine punctuation? Only `identifiers' can be used as macro names. Ferdinand Macros, ex-president
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
eppstein@garfield.columbia.edu (David Eppstein) (04/11/86)
In article <1458@cwruecmp.UUCP> ryan@cwruecmp.UUCP (Ryan McGuire) writes: > #define (-: /* > #define :-) */ Obviously the right way to do this is the following: #define cat(a,b) a/**/b #define (-: cat(/,*) #define :-) cat(*,/) Of course you might have to do it differently in ANSI C... There are already enough pictographs here that I shouldn't need to add another for the terminally humorless... -- David Eppstein, eppstein@cs.columbia.edu, seismo!columbia!cs!eppstein (note that the garfield in my headers is *not* the one in the UUCP map)
gemini@homxb.UUCP (Rick Richardson) (04/12/86)
If you want to use (-: and :-) as your comment delimiters, then you have to use something like "sed" to preprocess the code. Here's the sequence of commands you need to execute: sed -e 's/(-:/\/*/g' -e 's/:-)/*\//g' <source.c >xxx.c mv xxx.c source.c cc -c source.c Don't forget the "mv". It is the most critical part of getting the C right :-)
richw@ada-uts (04/15/86)
I don't have any suggestions, but I might be able to provide some insight... I think it depends on your implentation of C. You see, it depends on what the "lexical analyzer" of your particular compiler does to the text in the C-preprocessor lines. It would seem that when you say: #define foo <text here> that this has the same effect as doing a global replace, as editors do, of "foo" with "<text here>". However, at least some compilers I know of first cut up "<text here>" into lexical tokens, i.e. it breaks up the text into identifiers, strings, special C symbols (like '{' and '}'), and so on. This sequence of TOKENS, (not simply the sequence of characters) is then used wherever "foo" is encountered (this is actually more efficient since lexical analysis of "<text here>" is then only performed once for each occurence of "foo"). The important point, though, is that most lexical analyzers throw away comments. So, if your compiler does this, I see little hope of EVER being able to re-define C's comment delimiters. Judging by your description of the various things you tried, it seems as if your compiler does indeed lex the text of a define, so if I were you I'd give up and REALLY start hacking with "sed" or something. By the way, you'd think that what C is supposed to do here is well- defined. Well, unless the standard that ANSI's working on does so, I know of no such clear definition. A while ago, I played with the idea of writing a lexer for C and discovered that there were some ambiguities (within Kernighan & Ritchie, at least) as to what #define REALLY means. You might want to check Harbison & Steele; that C text might make mention of this sort of thing (I, unfortunately, don't own a copy, but I've looked at it and it's usually more specific than K&R about most things). Hope this helped, Rich Wagner
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