Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!think!mintaka!mit-eddie!uw-beaver!Teknowledge.COM!unix!hplabs!hp-sdd!hp-pcd!hpcvia!brianh From: brianh@hpcvia.CV.HP.COM (brian_helterline) Newsgroups: comp.lang.c Subject: Re: Re^2: Why nested comments not allowed? Message-ID: <31530001@hpcvia.CV.HP.COM> Date: 22 Feb 90 16:00:19 GMT References: <894@emunix.emich.edu> Organization: Hewlett-Packard Co., Corvallis, Oregon Lines: 62 misu_ss@uhura.cc.rochester.edu (What`s in a name?) writes: > {deleted} >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 On my compiler (MSC 5.1), it produced a syntax error! The line variable string should be declared as: char *string; not char *string[30] /* no semicolon */ -- 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 ----------