msanford
April 7th, 2003, 12:54 PM
Can anybody quickly explain to me why it is bad practice to do void main(int a, char**b) instead of int main(int a, char** b)? Where am I returning an int to anyway? Just a question thanks for your thoughts.
|
Click to See Complete Forum and Search --> : Whats wrong with void main(....)? msanford April 7th, 2003, 12:54 PM Can anybody quickly explain to me why it is bad practice to do void main(int a, char**b) instead of int main(int a, char** b)? Where am I returning an int to anyway? Just a question thanks for your thoughts. Paul McKenzie April 7th, 2003, 01:12 PM Originally posted by msanford Can anybody quickly explain to me why it is bad practice to do void main(int a, char**b) instead of int main(int a, char** b)?Because it isn't valid ANSI C++, and never was valid ANSI C++. It's just that VC++ and a few others have held onto this incorrect syntax, so as not to break other code. On the other hand, many compilers will reject the void main() and will properly report it as an error.Where am I returning an int to anyway? Just a question thanks for your thoughts. At program termination, the exit() function is called from main() with the return value. If no return value is specified, then a "return 0;" is implied. Regards, Paul McKenzie Andreas Masur April 7th, 2003, 01:17 PM Take a look at this thread (http://www.codeguru.com/forum/showthread.php?s=&threadid=220132)... galathaea April 7th, 2003, 05:05 PM Another particularly important problem with void main is that you will lower your potential for jobs. I for one have become so tied up recently with converting old demo projects to standard c++ so that they can compile for different machines on different compilers that I have made a conscious decision to not hire any potential developers who submit sample code with void main or ".h" standard headers, as these mistakes are occupying way too much of my time recently... mwilliamson April 7th, 2003, 05:55 PM you can't just do a find and replace? If you put a vc project in the root of c, then use find/replace with subfolders enabled? galathaea April 7th, 2003, 06:10 PM Here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_differences_in_iostream_implementation.asp) is an example for VC++ of the changes that occur when upgrading from the old ".h" libraries. Unfortunately, if you compound these code changes over many small projects which need to be integrated and include many of the other old header changes, your calculations equal "one big waste of time". mwilliamson April 7th, 2003, 06:36 PM thats no fun... at you will build up good copy and paste skills ;) msanford April 8th, 2003, 12:39 PM Thank you for your responses. I can see that while learning it may be easier to use void main. However it is incorrect and unprofessional to do this in code that others may rely on. Since standards are what make programs work together I for one will make a more consious effort to correct this flaw. Besides void is one more charecter than int. rsmemphis April 8th, 2003, 01:21 PM This is what people in the 80s did to us. I remember a magazine (for the Amiga) showing that void main(void){} will result in much smaller code size than int main(int a, char **b){} Of course, things like that are largely irrelevant today. I don't even think that void main(void) generates smaller code on today's executables anymore. stober April 8th, 2003, 01:50 PM VC++ 6.0 there is only one assembly instruction different -- int argc(...) with return 0 adds the instruction 00000 33 c0 xor eax, eax What difference does that trivel thing make in a 1-meg or larger program ???? muthuis April 11th, 2003, 10:30 PM Upon looking at this thread, I actually was thinking about a pertinent issue. How relevant is a c++ program size in today's computing environment? We talk of inline functions, object size, memory allocation in heap etc., But are they still relevant? Ofcourse a neatly written code is a maintainer's pleasure. But apart from this, are the above arguments/procedures/standards still needed? Andreas Masur April 12th, 2003, 04:26 AM Well...basically you are right. Nowadays, most of the time you do not need to care much whether your application will take some bytes more than needed. However, many people here also know how it was several years ago, where all these things were limited and you had to save every byte you could. As for myself, although there is plenty of system resources available I still try to not waste unnecessary resources... :cool: proxima centaur April 14th, 2003, 02:08 PM About memory economy, I think it has become less of an issue for small structures, but for large structure, programmer still have to be "size" conscious. For example, you won't be storing 12 copies of a 1280x1024 image, you'll store pointers or references to it instead. It's just common sense. But for smaller structures like strings or ints? nah... why bother. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |