Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-25-2003, 08:34 PM
|
#1
|
Member
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61
Rep:
|
void main(void)
Which is the different between
int main(void)
void main()
void main(void)?
|
|
|
10-25-2003, 09:04 PM
|
#2
|
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
int main( void ) doesn't take any arguments, and returns an integer which usually indicates success or failure. Usually you won't care much about what main's return value is, but I suppose you could use it to tell whoever called it whether it had an error or not. void main() and void main(void) are the same. The empty parentheses imply no arguments to main, just as with any other function. The void return value means you don't need to return anything from main, although I think the standard practice is to use an int return value (and some compilers will even force you to use int as the return value).
|
|
|
10-25-2003, 10:31 PM
|
#3
|
Member
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288
Rep:
|
Stick to int main() or int main(int argc, char** argv) since these are the ISO standards.
|
|
|
10-25-2003, 11:24 PM
|
#4
|
Member
Registered: Jul 2003
Location: Mexico City
Distribution: Slackware 9.1, SuSE 9.1
Posts: 248
Rep:
|
Don't forget that if you use
int main()
You must return some value when your main function is done...
int main()
{
return 0;
}
If you use void, however, you are not expected to do that. I strongly encourage you to use int, though
void main()
{
return;
}
|
|
|
10-26-2003, 12:37 AM
|
#5
|
Member
Registered: Mar 2003
Posts: 804
Rep:
|
well it's worth it to take a look and see what exactly main is returning to.
Code:
exit(main(argc, argv));
seeing this it is clear that main should ALWAYS return a value. however it is optional
for main to have argc,argv. if they are not there, void should be. so, you should have either:
Code:
int main(int argc, char **argv)
or
int main(void)
|
|
|
All times are GMT -5. The time now is 09:22 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|