4 ms·
Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).
by ahoka 3y ago
Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).
- fulafel 3y agoAnd there is no way for the callee to check the nr of passed args, unlike in Lua.
- sovietswag 3y agoGood reference for that: https://jameshfisher.com/2016/11/27/c-k-and-r/ https://jameshfisher.com/2016/11/27/c-k-and-r/ This was also used to implement variadic functions like printf before varargs, see https://retrocomputing.stackexchange.com/a/20517 https://retrocomputing.stackexchange.com/a/20517
- mdaniel 3y agothat's ... (amazing|C for ya) int foo() { return 0; } int main(int argc, char* argv[]) { return foo("alpha", "beta", 1); } $ gcc-13 -Wall -Werror -o foo foo.c # oh, sads $ clang -o foo ./foo.c ./foo.c:5:34: warning: too many arguments in call to 'foo' return foo("alpha", "beta", 1); ~~~ ^ ./foo.c:5:15: warning: passing arguments to 'foo' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] return foo("alpha", "beta", 1); ^ 2 warnings generated.
- deleted 3y ago[deleted]
- astrange 3y agoNo longer true in C23, it means void now.