USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

int main() vs void main()

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Jan 09, 2024 9:35 pm    Post subject: int main() vs void main() Reply with quote

The answer, in order to ensure that your program always behaves in a predicable manner, is to explicitly define the main program as int main().

Read why in the article at safercode.com.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
nukes
Linux Guru


Joined: 29 Aug 2024
Posts: 4558

PostPosted: Sat Jan 10, 2024 2:22 pm    Post subject: Reply with quote

you would think this goes without saying.... the calling convention on x86 returns values in eax, so if you declared the function void (which isn't what _start is expecting anyway) then the exit code will just be whatever happens to be in that register at the end of the function.

Link not working for me... not resolving.



_________________
Gentoo x86-64 2.6.29.1
FreeBSD 7-CURRENT
Arch x86 2.6.30
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sun Jan 11, 2024 2:58 am    Post subject: Reply with quote

The link is http://www.safercode.com/blog/2008/10/14/int-main-vs-void-main.html and it works. What you said is the point of the message. An int value is expected to be returned. void (no value), is incorrect, and an implicit declaration, HOPING that your compiler will return an int is asking way too much and could well yield incorrect results as well.

int as the function type is the correct answer.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse