esink@turia.dit.upm.es (Eric Wayne Sink) (10/15/90)
What does ANSI say about comments within tokens ? ie, is the following legal ? int variable; vari/* in the middle */able = 5; Also, does ANSI say anything about the preprocessor contructing tokens ? I can't think of an example of this right now, but it would be something like: #define macro(X) variX /* obviously, some operator is needed above, if this is legal at all */ macro(5) = 3; /* expands to: vari5 = 3 */ Finally, can anyone send me/point me to examples of C code which causes problems for parsers/preprocessors ? I've heard something of a C torture test... Thanks in advance, and please email iff these questions have been hashed over too many times. (if appropriate, perhaps someone could email FAQ to me ?) Eric W. Sink esink@turia.dit.upm.es
bhoughto@cmdnfs.intel.com (Blair P. Houghton) (10/15/90)
In article <383@goya.dit.upm.es> esink@turia.dit.upm.es (Eric Wayne Sink) writes >What does ANSI say about comments within tokens ? ie, is the >following legal ? >int variable; >vari/* in the middle */able = 5; No. The comment is whitespace. >Also, does ANSI say anything about the preprocessor contructing tokens >#define macro(X) variX >/* obviously, some operator is needed above [...] */ >macro(5) = 3; /* expands to: vari5 = 3 */ Token-pasting. Use the ## preprocessing operator as follows: #define macro(X) vari ## X /* there's the operator you wanted */ macro(5) = 3; /* becomes vari5 = 3 */ /* HOWEVER */ #define FOO BAR macro(FOO) = 3; /* becomes variFOO = 3, _not_ variBAR = 3 */ >Finally, can anyone send me/point me to examples of C code which >causes problems for parsers/preprocessors ? I've heard something of a >C torture test... Anything I've written in the past ten years should do it :-). >email FAQ to me ?) Just keep on reading this group. The abridged FAQ was posted today, and the full text will be around in about two weeks if the abridged version doesn't tell you enough. --Blair
esink@turia.dit.upm.es (Eric Wayne Sink) (10/16/90)
My apologies for posting the original message. It was pointed out that I wasted space for a useless question. I shall attempt to be more careful and will assume that this apology is worth its space. Eric
lerman@stpstn.UUCP (Ken Lerman) (10/16/90)
In article <383@goya.dit.upm.es> esink@turia.dit.upm.es (Eric Wayne Sink) writes: [...] >#define macro(X) variX >/* obviously, some operator is needed above, if this is legal at all >*/ > >macro(5) = 3; /* expands to: vari5 = 3 */ > [...] >Eric W. Sink >esink@turia.dit.upm.es Another post showed (I love it when I get to see the answers before I see the questions) the use of the ANSI ## operator to do this. Prior to ANSI, many compilers accepted: #define macro(X) vari/**/X to expand: macro(5) = 3; as: vari5 = 3; I don't know if this is "official" K&R or not, but it worked on a lot of machines. (Note that the comment must be of zero length for this to work.) Ken
henry@zoo.toronto.edu (Henry Spencer) (10/17/90)
In article <5689@stpstn.UUCP> lerman@stpstn.UUCP (Ken Lerman) writes: >#define macro(X) vari/**/X >... >I don't know if this is "official" K&R or not, but it worked on a lot >of machines... It was never K&R-sanctioned. Indeed, the detailed semantics of the preprocessor were very fuzzy until ANSI C nailed them down. And it worked on "a lot of machines" only so long as those machines were all using PCC, with the Reiser preprocessor. It generally did not work with independently-implemented compilers. -- "...the i860 is a wonderful source | Henry Spencer at U of Toronto Zoology of thesis topics." --Preston Briggs | henry@zoo.toronto.edu utzoo!henry