4 ms·
Removing K&R style function prototypes though is kind of big. I remember when one of the Objective-C upgrades started enforcing K&R. I don't think ObjC will be
by mojuba 5y ago
Removing K&R style function prototypes though is kind of big. I remember when one of the Objective-C upgrades started enforcing K&R. I don't think ObjC will be upgraded to C23 (ever, as it's a language being deprecated now I presume) so it will be stuck with K&R... while the rest will move on?
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?
- flohofwoe 5y agoIME ObjC (unlike C++) automatically supports the latest C standards, because ObjC just adds some syntax sugar on top of C, but otherwise doesn't 'mangle' its C subset into its own dialect like C++ does.
- melissalobos 5y ago>IME ObjC (unlike C++) automatically supports the latest C standards, 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).
- dgrunwald 5y agoWhat's being removed in C23 is the ancient K&R syntax for function definitions: 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.
- zh3 5y agoWow, that's annoying. There's a bunch of old code we have that'll need updating (written that way to keep the line lengths down).
- MawKKe 5y ago...can't you just configure your build system to compile those modules with pre-c23 standard?
- zh3 5y agoOf course. But one of the great things about C is that as a rule nothing breaks with compiler changes (as long as appropriate care has been taken) which this appears to violate.
- rightbyte 5y agoMaybe the compiler will add a extension flag? I mean the K&R declarations still need to be supported in the compiler for earlier standards.
- klyrs 5y agoAll the compilers I use have a default C version, and an optional flag to control which version to use. It's a non-issue.
- mojuba 5y agoAccording to the OP tweet though, `foo()` is now a function that takes no arguments.
- jesprenj 5y agoWouldn't int foo(void) be a function that takes no arguments and int foo() a function that takes an unknown number of arguments?
- suprjami 5y agoYes, that's the problem.
- suprjami 5y agoThat's a different thing. That's implied `foo(void)`.
- messe 5y agoIt WAS a different thing. That's changing in C23.
- leetrout 5y agoAgree the tweet makes it seem the behavior is changing. 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/1494812595064393731 https://mobile.twitter.com/__phantomderp/status/149481259506...
- zx2c4 5y agoHere's the document for that change: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm > 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() | ^~~~
- josephcsible 5y agoI'm particularly unhappy that K&R declarations are going away without https://www9.open-std.org/JTC1/SC22/WG14/www/docs/n2780.pdf https://www9.open-std.org/JTC1/SC22/WG14/www/docs/n2780.pdf being added to replace them. Now there's some functions that you can't write anymore.
- plorkyeran 5y agoObj-C can be compiled using any version of C (and Obj-C++ can be compiled using any version of C++). You already can use C2x with obj-c if you desire. I don't know what "enforcing K&R" means in this context, but if you think that Obj-C requires using K&R-style function definitions you're very confused about something.