Path: utzoo!attcan!uunet!snorkelwacker!think!zaphod.mps.ohio-state.edu!sunybcs!uhura.cc.rochester.edu!misu_ss From: misu_ss@uhura.cc.rochester.edu (What`s in a name?) Newsgroups: comp.lang.c Subject: Re: Re^2: Why nested comments not allowed? Summary: Use #define. Message-ID: <5372@ur-cc.UUCP> Date: 21 Feb 90 16:29:08 GMT References: <1523@wacsvax.OZ> <13706@cbnewsc.ATT.COM> <4286@jhunix.HCF.JHU.EDU> <4509@jarthur.Claremont.EDU> <4292@jhunix.HCF.JHU.EDU> Reply-To: misu_ss@uhura.cc.rochester.edu (What`s in a name?) Organization: Society for the Incurably Pompous Lines: 58 In article <4292@jhunix.HCF.JHU.EDU> barrett@jhunix.UUCP (Dan Barrett) writes: >In article <4509@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >>It seems to me that putting a start or end >>comment in a string literal (like above) is a HORRIBLE programming practice >>whether you can have nested comments or not. > > Oh yes? Well, what if you are writing a C program that generates >C code as its output? This is a common practice. > This leads me to a question on how compilers work... Do #defines get worked out before comments are discarded... I.E. if I write code thus: #define OPEN_COMMENT "/*" #define CLOSE_COMMENT "*/" main() { char *string[30] string = OPEN_COMMENT; printf("s% ", string); string = "This is a C comment"; printf("s% ", string); string = CLOSE_COMMENT; printf("s%\n", string); } will this produce the output: /* This is a C comment */ or will it simply do a newline and make string point to the return value of printf? (likely causing a seg fault if string is ever assigned again...) On gcc version 1.36 and cc (don't know version) running under SunOS4.0.3 this code produces the first output. Any compilers out there that do comment checking after filling out macros? If this always works then this is a possible solution to the problem... Obviously, you'll have to use string functions but is that so bad? If you are doing something that will output C code it's going to be pretty general in nature... There won't be a lot of cases where constant output is easiner than variable output. --mike -- Mic3hael Sullivan, Society for the Incurably Pompous -*-*-*-*- ...I know there are people in the world who do not love their fellow human beings and I *HATE* people like that! --Tom Lehrer