Why do I see so much C code that omits a return type for main? Why does it work? -



Why do I see so much C code that omits a return type for main? Why does it work? -

i went website compiles c online , saw main function declared without homecoming type.

i'm aware of questions concerning topic here, didn't find omitting homecoming type. tried compile code using gcc , worked.

does mean if don't set homecoming type on main, assume int (or other type)?

the c89 standard, preserve compatibility original k&r version of c did not have function prototypes know them, allowed functions implicitly homecoming int. function declared without explicit homecoming type (i.e., void, float, etc.) assumed compiler homecoming int.

thus, when main function declared without homecoming type, assumed homecoming type int. , good, since main supposed homecoming int, according standard.

however, changed in c99. default/implicit int rule removed language specification. functions without explicit homecoming type no longer assumed homecoming int.

that means modern compiler, adhering current version of c language specification, declaration of main without homecoming type invalid.

as why works on gcc, because default, gcc still adheres c89/c90 standard, unless explicitly specify -std=c99 compiler flag. , why still see online, well, there 2 reasons. first 1 i've given: legal in older versions of language specification, , lots of old code hasn't been updated. sec reason that, unfortunately, there lots of bad c code online , in books. may have found some.

c main

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -