Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: // comments and \ Date: Tue, 01 Dec 2015 10:49:48 -0800 Organization: None to speak of Lines: 69 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="31788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+Ip5061FVySJZIyc5gc0U" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jEtZLNe4U+sbKmdtRQIdPDDDDic= sha1:umv7ynI37QKqvCfNokqJXwpc9WE= Xref: csiph.com comp.lang.c:77545 Keith Thompson writes: > BartC writes: >> This is a problem I came across with an assembler, which caused me some >> trouble to sort out. >> >> Then I thought I'd try it with C, convinced it couldn't be as silly, but >> apparently it was! >> >> Here: >> >> // this is a comment ... \ >> puts("Hi!"); >> >> the continuation character at the end of the comment means the following >> line isn't compiled (which can give puzzling results as you can imagine). > [...] > > It's actually a bit worse than that. Consider this program: > > #include > int main(void) { > // \ > puts("This is a comment"); > puts("This is not a comment"); > } > > You can't see it, but there's a space after the backslash on line 3 > (assuming it's not stripped by somebody's news software). Because the > line doesn't end with a backslash, it's not a continuation line, so the > output *should* be: > > This is not a comment OOPS! > tcc produces that output, but both gcc and clang ignore the trailing > blank and produce this output: > > This is a comment > This is not a comment OOPS! > (clang warns about the trailing space.) > > I prefer the gcc/clang behavior, but it's not consistent with the > standard -- though I suppose you could argue that the trailing blanks > could be removed in translation phase 1. Sorry, I got that backwards. The output (if my reading of the standard is correct) *should* be: This is a comment This is not a comment When compiled with gcc or clang, the output is: This is not a comment > In any case, the solution is straightforward: Don't Do That. I shouldn't post before I've had enough coffee. I expect I'll have had enough coffee in another ten years or so. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"