Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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).


Good reference for that: 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


that'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.


No longer true in C23, it means void now.


And there is no way for the callee to check the nr of passed args, unlike in Lua.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: