• AVR Freaks

Return type of main is not int

Author
rigvedmayekar
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2009/04/24 00:17:36
  • Location: 0
  • Status: offline
2009/04/24 02:51:24 (permalink)
2 (1)

Return type of main is not int

hello every1 ther!!!
 
I m working with PIC24 controller and using C-30 compiler for code development...
everytime when i compile my code, i get the following warning...
 
"Return type of main is not int"
Can nybody tell me, why is it so? cant we begin the code with void main()?
 
Thanks in advance for givin attention to my query.....
 
#1

7 Replies Related Threads

    sequoia
    Super Member
    • Total Posts : 222
    • Reward points : 0
    • Joined: 2008/08/04 17:17:09
    • Location: 0
    • Status: offline
    RE: Return type of main is not int 2009/04/24 03:41:12 (permalink)
    0
    Because the function prototype specifies “int main(void)”
    #2
    kobuseng
    Super Member
    • Total Posts : 399
    • Reward points : 0
    • Joined: 2007/02/13 08:08:22
    • Location: South Africa
    • Status: offline
    RE: Return type of main is not int 2009/04/24 05:06:00 (permalink)
    0
    This has perhaps something to do with in DOS each command or program has to return a exit code for use in batch processing. For that matter I remember something about every command and program had to be able to accept at least one input parameter, even if it was never used.

    Neverless that is why main returns something and not just void.
    #3
    leon_heller
    Super Member
    • Total Posts : 6411
    • Reward points : 0
    • Joined: 2004/08/17 13:19:45
    • Location: St. Leonards-on-Sea, E. Sussex, UK.
    • Status: offline
    RE: Return type of main is not int 2009/04/24 05:09:20 (permalink)
    0
    Interestingly, C18 wants void main(void), IIRC.

    leon

    Leon Heller
    G1HSM

    #4
    BitWise
    Super Member
    • Total Posts : 1238
    • Reward points : 0
    • Joined: 2004/11/09 13:24:20
    • Location: UK
    • Status: offline
    RE: Return type of main is not int 2009/04/24 06:00:28 (permalink)
    0
    On a real operating systems the return value of main is returned to parent process so that it can tell if the program executed correctly (e.g. main returned zero) or if it failed (e.g. any non-zero return value).

    ANSI C I believe allows main to be declared either returning int or void (the language lawyers will no doubt confirm or deny this).

    The return value of main an embedded application is pretty meaningless as there is no parent process to return the value to, so having main return void is the sensible way to define it.

    Throughout your life advance daily, becoming more skillful than yesterday, more skillful than today. This is never-ending.

    Yamamoto Tsunetomo (1659-1719)
    #5
    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Return type of main is not int 2009/04/24 07:24:31 (permalink)
    #6
    aschen0866
    Super Member
    • Total Posts : 4496
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Return type of main is not int 2009/04/24 07:28:35 (permalink)
    #7
    dhenry
    Super Member
    • Total Posts : 4994
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Location: Colorado
    • Status: offline
    RE: Return type of main is not int 2009/04/24 07:56:15 (permalink)
    0
    ORIGINAL: BitWise

    ANSI C I believe allows main to be declared either returning int or void ...

    ... or anything else.  From the standard:

    "In a freestanding environment (in which C program execution may take place without any
    benefit of an operating system), the name and type of the function called at program
    startup are implementation-defined."

    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5