Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in c: func(void) vs. func() [duplicate]

When a C function does not accept any arguments, does it have to be declared/defined with a "void" parameter by the language rules? PC-Lint seems to have problems when there's nothing at all in the argument-list, and I was wondering if it's something in the language syntax that I don't know about.

Edit: I just found a duplicate (back-dupe? it came first) question, C void arguments, which has more answers and explanations.

like image 200
noamtm Avatar asked Jul 22 '09 08:07

noamtm


1 Answers

void means the function does not take any parameters. For example,

int init (void)
{
    return 1;
}

This is not the same as defining

int init ()
{
    return 1;
}

because in the second case the compiler will not check whether the function is really called with no arguments at all; instead, a function call with arbitrary number of arguments will be accepted without any warnings (this is implemented only for the compatibility with the old-style function definition syntax, pre-ANSI).

like image 199
dfa Avatar answered Sep 21 '22 13:09

dfa