Liste des Groupes | Revenir à cl c |
Bart <bc@freeuk.com> writes:
Let's put it this way: if somebody asked me what the rule was, I wouldn't be able to tell them.OK, if it's so simple, explain it to me.I'll pretend that was a sincere question.
You seem to be under the impression that a closing brace shouldConsistency? I posted a bit of Algol68 the other day; each function definition needed a semicolon, to separate it from the next.
either always or never be followed by a semicolon. I don't know
where you got that idea.
Braces ("{", "}") are used in different contexts with different
meanings. They're generally used for some kind of grouping (of
statements, declarations, initializers), but the distinct uses are
distinct, and there's no particular reason for them to follow the
same rules.
Apparently the first line here needs a semicolon after }, the secondYes. The first is a declaration, and a declaration requires a
doesn't:
>
int X[1] = {0};
void Y() {}
semicolon. I suppose the language could have a special-case rule
that if a declaration happens to end with a "}", the semicolon is
not required, but that would be silly.
The second is a function definition (and can only appear at file
scope). Function definitions do not require or allow a semicolon
after the closing "}". Why should they?
Consistency again? But then you'd get this: if () {}; else {};. It would be incompatible with how it works now.Similarly here:Because that's what the grammar says.
>
if (x) y;
if (x) {}
>
Why?
>
"Because that's what the grammar says" isn't a valid answer.
Not all statements require a closing semicolon. In particular,
compound statements do not, likely because the closing
"}" unambiguously marks the end of the statement. Sure, the
language could have been specified to require a semicolon, but why?
(I'll note that languages that use "begin"/"end" rather than "{"/"}"That's my A68 example.
often require a semicolon after the "end".)
And you can add a semicolon after a compound statement if you likeBut not here I guess: if () {}; else ...
(it's a null statement),
Of course you know all this.I'm aware of how messy and conistent it is. I've said that languages that use ";" as a separator probably fair better, but are still not ideal because the last statement of a block is now an annoying special case.
I said that my generated code has to use ":;" after each label; it looks weird.Please don't say the label is only defined to be a prefix to anotherThe label is only defined to be a prefix to another statement.
statement. I asking why it was done like that.
It was simple to define it that way, and not particularly
inconvenient to add a semicolon if you happen to want a label at
the end of a block. I'd be surprised if this rule has ever actually
caused you any inconvenience.
But you'll be delighted to know that C23 changed the grammar for aNo, that's amazing. Presumably, some people must complained about it (maybe it actually caused some inconvenience!), and it eventually got fixed.
compound statement, so a label can appear before any of a statement,
a declaration, or the closing "}". So now you have exactly what you
want. (Just kidding; you'll still find a way to be angry about it.)
Les messages affichés proviennent d'usenet.