Liste des Groupes | Revenir à cl c |
On 04/12/2024 12:56, Michael S wrote:On Tue, 3 Dec 2024 17:42:20 -0000 (UTC)
antispam@fricas.org (Waldek Hebisch) wrote:
David Brown <david.brown@hesbynett.no> wrote:On 01/12/2024 17:57, Michael S wrote:>On Sun, 1 Dec 2024 15:34:04 +0100>
David Brown <david.brown@hesbynett.no> wrote:>>
I can see some advantages in a language being happy with any
order of function definition, without requiring forward
declarations to use a function before it is defined. But C is
not like that, and I cannot honestly say it bothers me one way
or the other. And apparently, it does not particularly bother
many people - there is, I think, no serious impediment or
backwards compatibility issue that would prevent C being
changed in this way. Yet no one has felt the need for it - at
least not strongly enough to fight for it going in the standard
or being a common compiler extension.
>
>
I think, arguing in favor of such change would be easier on top
of the changes made in C23.
Before C23 there were, as you put it "no serious impediment or
backwards compatibility issue". After C23 we could more
categorical claim that there are no new issues.
Does that mean there was something that you think was allowed in C
before C23, but not after C23, that would potentially be a problem
here?
>
What, specifically, are you thinking of?
Michael probably meant 'constexpr'.
No, I am afraid of cases where function is used without prototype
and then there is conflicting definition later in the module.
Of course, it's UB, but in practice it could often work fine.
Something like that:
static int bar();
int foo(void)
{
return bar(42);
}
static int bar(int a, int b)
{
if (a == 42)
return -1;
return a - b;
}
Under c23 rules the code above is illegal, but before c23 it's
merely a UB.
I think it is always better to have a hard error than to allow UB!
But this is not actually anything to do with ordering of functions or
declarations. You could omit "foo" entirely and the code is still an
error in C23, because "static int bar();" /is/ a prototype
declaration in C23 - it means the same as "static int bar(void);".
Les messages affichés proviennent d'usenet.