Dale Johannesen
2008-Mar-25 17:08 UTC
[LLVMdev] Apple's GCC and .s/.S files in llvm-test (fwd)
On Mar 24, 2008, at 3:18 PM, David Vandevoorde wrote:> > On Mar 24, 2008, at 5:40 PM, Dale Johannesen wrote: > [...] >> I don't see a good way to do >> full-line comments that works both if you run the preprocessor and if >> you don't. > > > Could you use "##" instead of "#"?Pragmatically, that works (as I'm sure you know). Digging into the legalities of C99 I'm not sure that it's guaranteed to work, though. Unknown directives actually match the "non-directive" case in the grammar in 6.10; while nothing is said anywhere about semantics that I can find, I'm not sure why gcc feels this should be a hard error at all....
David Vandevoorde
2008-Mar-25 18:04 UTC
[LLVMdev] Apple's GCC and .s/.S files in llvm-test (fwd)
On Mar 25, 2008, at 1:08 PM, Dale Johannesen wrote:> > On Mar 24, 2008, at 3:18 PM, David Vandevoorde wrote: > >> >> On Mar 24, 2008, at 5:40 PM, Dale Johannesen wrote: >> [...] >>> I don't see a good way to do >>> full-line comments that works both if you run the preprocessor and >>> if >>> you don't. >> >> >> Could you use "##" instead of "#"? > > Pragmatically, that works (as I'm sure you know). Digging into the > legalities of C99 I'm not sure that it's guaranteed to work, though. > Unknown directives actually match the "non-directive" case in the > grammar in 6.10; while nothing is said anywhere about semantics that I > can find, I'm not sure why gcc feels this should be a hard error at > all...."##" is a punctuator (6.4.6) and therefore a preprocessing token of its own (6.4/1). A line that starts with "##" is therefore a text-line in 6.10/1 parlance (i.e., it doesn't match the "# non-directive" rule), and so yes, I think it's guaranteed to work on the preprocessor side of things. (I know next to nothing about the assembler side of things.) I don't know either why GCC faults non-directive "# ..." cases. Maybe it's a C89 leftover, or maybe it has to do with the older "# <line- number>" forms. Daveed
Dale Johannesen
2008-Mar-25 18:18 UTC
[LLVMdev] Apple's GCC and .s/.S files in llvm-test (fwd)
On Mar 25, 2008, at 11:04 AM, David Vandevoorde wrote:> > On Mar 25, 2008, at 1:08 PM, Dale Johannesen wrote: >> >> On Mar 24, 2008, at 3:18 PM, David Vandevoorde wrote: >> >>> >>> On Mar 24, 2008, at 5:40 PM, Dale Johannesen wrote: >>> [...] >>>> I don't see a good way to do >>>> full-line comments that works both if you run the preprocessor and >>>> if >>>> you don't. >>> >>> >>> Could you use "##" instead of "#"? >> >> Pragmatically, that works (as I'm sure you know). Digging into the >> legalities of C99 I'm not sure that it's guaranteed to work, though. >> Unknown directives actually match the "non-directive" case in the >> grammar in 6.10; while nothing is said anywhere about semantics >> that I >> can find, I'm not sure why gcc feels this should be a hard error at >> all.... > > "##" is a punctuator (6.4.6) and therefore a preprocessing token of > its own (6.4/1). > > A line that starts with "##" is therefore a text-line in 6.10/1 > parlance (i.e., it doesn't match the "# non-directive" rule), and so > yes, I think it's guaranteed to work on the preprocessor side of > things. (I know next to nothing about the assembler side of things.)Ah right, ## is still a token although it can appear only in restricted places...ok, now I like this. This is documented to work in the assembler, so it looks good. Thanks.
Chris Lattner
2008-Mar-25 18:28 UTC
[LLVMdev] Apple's GCC and .s/.S files in llvm-test (fwd)
On Tue, 25 Mar 2008, Dale Johannesen wrote:>> On Mar 24, 2008, at 5:40 PM, Dale Johannesen wrote: >> [...] >>> I don't see a good way to do >>> full-line comments that works both if you run the preprocessor and if >>> you don't. >> >> >> Could you use "##" instead of "#"? > > Pragmatically, that works (as I'm sure you know). Digging into the > legalities of C99 I'm not sure that it's guaranteed to work, though. > Unknown directives actually match the "non-directive" case in the > grammar in 6.10; while nothing is said anywhere about semantics that I > can find, I'm not sure why gcc feels this should be a hard error at > all....I think that this is an extremely clever hack, and is nice and simple. It works because ## is a token that just gets passed through when not in a macro replacement list. Because of maximal munch, it prevents the preprocessor from seeing it as a #. Dale, do you see any problem with changing the "comment character" to "##"? -Chris -- http://nondot.org/sabre/ http://llvm.org/