Is it necessary the function main() should return int?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gobi Sakthivel
    New Member
    • Jan 2013
    • 26

    Is it necessary the function main() should return int?

    If so what is the reason, and the returning int value indicates wat?
  • swapnali143
    New Member
    • Mar 2012
    • 34

    #2
    If you are working with TC then no need of return 0 because default return type of main() is void i.e. it does not return value...
    But under Linux platform if you are using gcc then you need to write return 0 because main() returntype is int

    Comment

    • Anas Mosaad
      New Member
      • Jan 2013
      • 185

      #3
      Even with gcc on my Ubuntu linux I'm not required to specify a return for the main.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Refer to the C FAQ:

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          The standards say main() returns an int. And the only values are supposed to 0 or 1.

          main() returning a void is an old Microsoft whiz-bang not even they use anymore.

          The idea is that the code that calls main() has access to the returned int but I've looked into the Microsoft OS code and they don't use the returned int at all.

          The big deal is that when you return void your function cannot be used as a RVAL. If some OS you don't know about starts to use main() as an RVAL, then none of your code will run on that machine.

          This is very much like dragons inside the earth swallowing your alive unless they are appeased by some ritual. Why take a chance? Just appease those dragons.

          Comment

          Working...