Could someone also explain what this means for pure C in terms of compatibility? If there's
void foo();
would the meaning of it depend on which C standard is activated?Could someone also explain what this means for pure C in terms of compatibility? If there's
void foo();
would the meaning of it depend on which C standard is activated? int max(a, b)
int a, b;
{
return a>b?a:b;
}
My understanding is that C23 does not change the meaning of function declarations. So "void foo();" remains a declaration of a function accepting an unknown number of parameters.Edit: parent is correct it IS changing
> We could make this change because foo() decls and definitions had been deprecated since C89/99, longer than I've been alive.
> Implementations will likely warn on foo() decls for a while, and error if someone calls it with foo(too, many, args);.
https://mobile.twitter.com/__phantomderp/status/149481259506...
> In this proposal, a function declarator without a parameter list declares a prototype for a function that takes no parameters (like it does in C++).
And it seems like gcc implements this under -std=c2x now:
zx2c4@thinkpad /tmp $ cat a.c
int blah()
{
return 7;
}
int main(int argc, char *argv[])
{
return blah(argc);
}
zx2c4@thinkpad /tmp $ gcc -std=c17 a.c
zx2c4@thinkpad /tmp $ gcc -std=c2x a.c
a.c: In function ‘main’:
a.c:8:16: error: too many arguments to function ‘blah’
8 | return blah(argc);
| ^~~~
a.c:1:5: note: declared here
1 | int blah()
| ^~~~int foo(int, int) is a function taking two arguments. int foo(int) is a function taking one argument. int foo() ought to mean a function taking no arguments, not a function with an unspecified number of arguments!
This is only true as long as the changes in C aren't conflicting with ObjC. In the future if ObjC is deemed dead by the council it won't have to worry about such things. So C58 may have tons of things that don't work in ObjC98 (or whatever the ObjC version is).