I’m confused about why we need to pass void into C functions:
int f(void) { return 0; }
versus
int f() { return 0; }
What is the proper thing to do and why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In C,
int f()is an old-style declaration. It says thatfexpects a fixed but unspecified number and type(s) of arguments. For example, givenint f() { return 0; }, the compiler won’t complain aboutf(42), orf("hello, world")(though the behavior of such a call is undefined).int f(void)explicitly says thatftakes no arguments.(C++ has different rules; Stroustrup wasn’t as concerned about backward compatibility with old C code.)