LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 10-25-2003, 08:34 PM   #1
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Rep: Reputation: 15
void main(void)


Which is the different between
int main(void)
void main()
void main(void)?
 
Old 10-25-2003, 09:04 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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).
 
Old 10-25-2003, 10:31 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Stick to int main() or int main(int argc, char** argv) since these are the ISO standards.
 
Old 10-25-2003, 11:24 PM   #4
Jose Muņiz
Member
 
Registered: Jul 2003
Location: Mexico City
Distribution: Slackware 9.1, SuSE 9.1
Posts: 248

Rep: Reputation: 32
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;
}
 
Old 10-26-2003, 12:37 AM   #5
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
meaning of void* kpachopoulos Programming 3 10-12-2005 04:48 PM
void pointers suchi_s Programming 9 11-08-2004 03:05 PM
void? Patchorus Programming 9 10-25-2003 07:24 PM
void pointer help gonnaWorkItOut Programming 1 10-12-2003 11:52 AM
void foo(void) and void foo() lackluster Programming 9 02-15-2003 10:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration