| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | int main PLEASE |
On (24 Nov 94) Paul Edwards wrote to Rafael Solomon... ac>> int main(void) RS> I have only started programming in C so I haven't used that can you RS> tell me the advantages of that compared to "void main()" PE> It's not a matter of advantages, it's a matter of only one way PE> is correct, and that's int main(void). The ISO C standard only PE> says "int main(void)" and "int main(int argc, char **argv)" are PE> valid. If your compiler supports a NON-STANDARD extension, PE> that's it's problem. PE> You should always exit main() with a return (0) [or a similar PE> strategy] in order to let the operating system know that it PE> finished OK. Your program did finish OK, didn't it? Failure PE> to set a return code will cause the MSDOS errorlevel to be PE> set to a random value, assuming you are using MSDOS. That is PE> not what a good program does. Hi Rafael Don't mind Paul, he'd burn all Borland users at the steak (sic) if he could. We fought about this a while ago, and the arguments that convinced me that int main() was better than void main() ran something like: 1. int main() returns an int value to the calling program / operating system, and you (the programmer) are in control of what that return value is. You may say (as I did) that you have no use for such a feature, but one day you may write a non-trivial program that other people will use. You cannot control how those other users will use your program, and there's a good chance that some of them will be looking for a return value to detect fatal problems (missing input files, for instance). Using void main(), and/or failing to return a predictable error value, can annoy these users enough for them to drop your program. Using int main(), and mentioning in your docs just what your return values mean, can be quite helpful to an end user. 2. Using int main() and returning an error value is quite easy to do, and helps you think about how and why you are exiting your program, so why not get into the habit of doing it? Cheers --- PPoint 1.88* Origin: Silicon Heaven (3:711/934.16) SEEN-BY: 711/809 934 @PATH: 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.