sizeof problem

Started by
17 comments, last by GameDev.net 18 years ago
Yes it works (on some compilers), but it's not valid C++ nor C.
The C++ standard allows one of the following signatures:

int main()int main(int argc, char* argv[])


And why the extra (void) ? Just curious...
Advertisement
Quote:Original post by Konfusius
Yes it works (on some compilers), but it's not valid C++ nor C.

I agree with that. I guess I should change [smile]
Quote:Original post by rpg_code_master
Quote:Original post by Konfusius
Yes it works (on some compilers), but it's not valid C++ nor C.

I agree with that. I guess I should change [smile]


One thing less to worry about! [lol]
Quote:Original post by rpg_code_master
Quote:Original post by Konfusius
BTW, (sorry can't resist :P) there has never been a void main().
And I am curious to know what an explicit void parameter should communicate...

It works, I use it all the time.

I just double tested on Visual Studio 2005 here at work, and it runs fine.


Quote:
ISO14882(C++ standard) section 3.6.1.2
An implementation shall not define the main function. The function shall not be overloaded. It shall have a return type of int but otherwise it's type is implementation defined. All implementations shall allow both of the following definitions of main:
int main() { /*...*/ }
int main(int argc, char* argv[]) { /*...*/ }


Quote:Original post by Konfusius
And why the extra (void) ? Just curious...
It's an old C thing. In C, before the C99 (Or Csomething) standard, any function not taking any arguments had to be declared as return_type function_name(void).
Steve: Thanks for clarifying!
Thank You Everyone
A class can have zero size. When one class derives from another class that doesn't require any storage, that base class may take up 0 space. Here are two decent links on the topic:

The Empty Base Class Optimization
Empty Member C++ Optimization
Quote:Original post by Evil Steve
Quote:Original post by Konfusius
And why the extra (void) ? Just curious...
It's an old C thing. In C, before the C99 (Or Csomething) standard, any function not taking any arguments had to be declared as return_type function_name(void).


Never "had to". "int main()" was always legal, it just meant "takes an unspecified number of arguments" so, if you were to call main() (which is legal in C), you wouldn't get any error checking (types, number, order) on the parameters you passed. More an issue with functions other than main().

This topic is closed to new replies.

Advertisement