| Deutsch English Français Italiano |
|
<viqq95$164ug$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Wed, 4 Dec 2024 23:57:25 +0000
Organization: A noiseless patient Spider
Lines: 119
Message-ID: <viqq95$164ug$1@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me>
<87frnbt9jn.fsf@nosuchdomain.example.com> <viaqh0$nm7q$1@dont-email.me>
<877c8nt255.fsf@nosuchdomain.example.com> <viasv4$nm7q$2@dont-email.me>
<vibr1l$vvjf$1@dont-email.me> <vic73f$1205f$1@dont-email.me>
<20241129142810.00007920@yahoo.com> <vicfra$13nl4$1@dont-email.me>
<20241129161517.000010b8@yahoo.com> <vicque$15ium$2@dont-email.me>
<vid110$16hte$1@dont-email.me> <vifcll$1q9rj$1@dont-email.me>
<vifiib$1s07p$1@dont-email.me> <87ldwx10gv.fsf@bsb.me.uk>
<vimtt4$27vv$1@dont-email.me> <vin7r2$49d1$2@dont-email.me>
<vinalt$5qoh$1@dont-email.me> <vipgns$rjqn$1@dont-email.me>
<viqbl8$12mum$1@dont-email.me> <viqfuh$131h8$2@dont-email.me>
<87ttbj12ec.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 05 Dec 2024 00:57:25 +0100 (CET)
Injection-Info: dont-email.me; posting-host="12866f4cee3d02926546f0c9d8eee755";
logging-data="1250256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GF0lALymZOELh+SvOzksT"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GyTYoqL5TDpRuE+yrnmgsgsLF8E=
Content-Language: en-GB
In-Reply-To: <87ttbj12ec.fsf@nosuchdomain.example.com>
Bytes: 6045
On 04/12/2024 22:58, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
>> OK, if it's so simple, explain it to me.
>
> I'll pretend that was a sincere question.
Let's put it this way: if somebody asked me what the rule was, I
wouldn't be able to tell them.
> You seem to be under the impression that a closing brace should
> 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 second
>> doesn't:
>>
>> int X[1] = {0};
>> void Y() {}
>
> Yes. The first is a declaration, and a declaration requires a
> 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? I posted a bit of Algol68 the other day; each function
definition needed a semicolon, to separate it from the next.
>> Similarly here:
>>
>> if (x) y;
>> if (x) {}
>>
>> Why?
>>
>> "Because that's what the grammar says" isn't a valid answer.
>
> Because that's what the grammar says.
>
> 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?
Consistency again? But then you'd get this: if () {}; else {};. It would
be incompatible with how it works now.
So overall it's just messy. It works for BEGIN/END when semicolon is a
separator, rather than a terminator. So you write END ELSE not END; ELSE.
But because C uses ";" as a terminator, it's made a rod for its own back.
> (I'll note that languages that use "begin"/"end" rather than "{"/"}"
> often require a semicolon after the "end".)
That's my A68 example.
> And you can add a semicolon after a compound statement if you like
> (it's a null statement),
But not here I guess: if () {}; else ...
> 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.
So it's an interesting language design problem.
My own made a compromise here: use ";" as separator, but introduce some
rules so that explicit ";" is rarely need. I think that wins.
Meanwhile, if I compile this:
void F(){}; void G(){};
My compilers report a syntax error. But gcc passes it by default. So I
take what the grammar says more seriously than gcc!
IS ";" between function definitions legal or not? If not, then fail the
program.
>> Please don't say the label is only defined to be a prefix to another
>> statement. I asking why it was done like that.
>
> The label is only defined to be a prefix to another statement.
> 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.
I said that my generated code has to use ":;" after each label; it looks
weird.
> But you'll be delighted to know that C23 changed the grammar for a
> 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.)
No, that's amazing. Presumably, some people must complained about it
(maybe it actually caused some inconvenience!), and it eventually got fixed.
Of course, if it was just me, then it would be pointless ranting. 'How
hard is to add the semicolon?'
Well, 'How hard is it to delete the semicolon' from my above example?