R
Radamanthe
santosh said:Harald said:The compiler must behave as if comments are gone, but that only meanssantosh said:Ben Bacarisse wrote:
santosh said:
<snip>
Out of curiosity, can you name a compiler that emits this diagnostic?
[for the while(condition); construct]
Not off the top of my head, no.
and neither can I, but I can confirm the exited once. Might have been
an old Borland one.
<snip>
If so, then I am also disremembering that one way to
quell the warning was to add a space: while(condition) ;
The one I remember shut up with a comment and I still often write:
while (condition) /* do nothing */;
Interesting, seeing as, logically, comments are not supposed to be
present at compilation proper.
they have no effect noticeable from a strictly conforming program.
They may cause other effects, including the number and types of
warnings, so long as those warnings are not required by the standard.
I personally think it's odd for the compiler to be influenced by
comments. I don't see why they should have any effect on code around
them.
For a related example, at least one compiler warns for
switch (i)
{
case 0:
a();
case 1:
b();
}
but does not for
switch (i)
{
case 0:
a();
/* FALLTHROUGH */
case 1:
b();
}
(Okay, the version I'm using warns for both. That's a bug, and one
which is not present in the last official release, as far as I can
tell.)
How so? If it warns at all, I'd expect it to warn for both, regardless
of the intervening comment.
These are just warnings. Actually, this does not change the generated
code at all. I suppose the compiler decides not to warn when there is a
comment before the following case, because an experienced programmer
using this behavior of switch/case generally puts a comment there, just
to inform that the absence of the break statement is intentional (and
not an obvious bug as it is generally). Exploiting this behaviour is
very uncommon practice, so best to warn the reader.
Anyway, I don't think this is a "so wise" feature of the compiler. Lots
of people may have the habit to put comments above cases, thus
forgetting a break would almost certainly pass silently.