Not so. In a definition, an unnamed void argument, and an empty argument list both mean the same thing.
So this will not compile with a "too many arguments" error:
Code:int func(){
return 0;
}
int main(){
func(1);
}
Printable View
Are you sure you did not compile as C++? It works for me when compiling as C.Quote:
Originally Posted by vart
EDIT:
Wait a minute, I assumed that King Mir meant 'this will not (compile with a "too many arguments" error)' (which does not really make sense, I suppose), but maybe King Mir meant 'this will (not compile) with a "too many arguments" error', in which case the reason why this is not so is that the definition is also a declaration.
EDIT #2:
hmm... but the language of C99 seems to indicate otherwise:
The wording "not part of a definition" seems to say that although a definition is a declaration, the fact that it is a definition trumps the fact that it is a declaration for the interpretation of an empty parameter list. If this is so (and also in C90), then gcc and MSVC are both non-conformant in this area.Quote:
Originally Posted by Section 6.7.5.3, Paragraph 14
I compiled it as C
VS2005 gives no errors
gcc port used in CodeBlocks - gives the error specified by King Mir
What is the version of gcc? The MinGW port of gcc 3.4.5 did not emit such an error for both C90 and C99 mode with -Wall and -pedantic tacked on.Quote:
Originally Posted by vart
ok I played a little with the CodeBlocks installation to see exactly which gcc is configured, what switches are set, and finally - what command line it uses to compile a file.
Here is it:
1. gcc is 3.4.5 and it does not show the error. (I have running it from command prompt)
2. CodeBlocks on some reason starts g++ to compile the c-file
So - about the second - how do I tell to CodeBlocks that *.c files should be compiled as C and not C++?
I think this might work: click on the .c file and select "Properties...". Click on the "Advanced" tab and change "CPP" to "CC" for the "Compiler variable" setting.Quote:
Originally Posted by vart
EDIT:
No, Code::Blocks does not seem smart enough to use gcc instead of g++ in that case.
My take on the whole was:
I could be wrong, though.Code:void fun(void); // No parameters
void fun(); // No parameter information (infinite parameters)
void fun(void) { } // No parameters
void fun () { } // No parameters
Although VS would let the last example compile.