4 ms·
One K&RC construct can sneak into new C by accident. A lost C++ developer might wander into a C program and write: void fun() { } which is fully declared i
by kazinator 3y ago
One K&RC construct can sneak into new C by accident. A lost C++ developer might wander into a C program and write:
void fun() { }
which is fully declared in C++, but in C it is an old-style function definition that doesn't declare anything about its arguments.
- pjmlp 3y agoIn C23 has the same semantics as in C++.
- el_pollo_diablo 3y agoNot exactly. As of C17, the function definition you wrote implies that the function has no arguments, just like in C++. However, a declaration that is not part of a definition, like void fun(); (which you typically find in a header file) indeed does not say anything about the function's arguments. You have to write void fun(void); to specify that the function takes no arguments. For consistency, you can (and probably should) also use that style in the function's definition, but you don't have to. Anyway, C23 will align C's behavior with C++: void fun() will mean the same thing as void fun(void), whether as part of a function definition or not.
- kazinator 3y agoI have N3096.pdf (April Fool's 2023 draft) perpetually open; will check it.