Different conventions for main() in C -


this question has answer here:

my exposure programming has been java,where have not encountered (up now) different conventions writing main method.i have been following sources learning c (k&r , c programming modern approach) use different forms of main method (function).

k&r version now:

main() {     blah blah blah; } 

c programming modern approach

int main() {     blah blah blah;     return 0; } 

or

int main() {     blah blah blah;      //returns nothing } 

to make matters more confusing have seen people :

int main(void) {     blah blah blah; } 

while either returned 0 or did not. don't in uneducated assumption think standards issue maybe bit more conceptual or deep. shed light on issue?

  • k&r style outdated , isn't correct according c standard more.

  • valid signatures

    int main(void) 

    and

    int main(int argc, char *argv[]) 

    or, equivalent because array type in function adjusted pointer type anyways:

    int main(int argc, char **argv) 
  • the signature

    int main() 

    happens valid well, because empty argument list means any number of arguments, aren't described *). afaik, subject change, don't write way. writing void how express this function doesn't take arguments in c.

  • implementations of c free provide other implementation-defined entry points. 2 listed above ones guaranteed standard.

  • c99 introduced special rule main() states if function doesn't return anything, value of 0 returned implicitly. only in main, can skip return. advice is: don't. it's confusing. opinion.


*) note different in c++, nothing between parantheses indeed means: no arguments.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -