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 09:21:12 -0800 Organization: None to speak of Lines: 51 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="3052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/UH9uqZHRz6ouuirVevaJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:+jOO6s67TMY4xlqRl9XEAKQTajM= sha1:pV8FLZJOdXNf5MUUwMveVj22hVc= Xref: csiph.com comp.lang.c:77533 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 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 (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. In any case, the solution is straightforward: Don't Do That. -- 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"