home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 21824 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.0 KB  |  52 lines

  1. Path: sparky!uunet!pipex!warwick!uknet!miclon!nreadwin
  2. From: nreadwin@micrognosis.co.uk (Neil Readwin)
  3. Newsgroups: comp.os.vms
  4. Subject: Re: C problem
  5. Message-ID: <C1BCpF.GnA@micrognosis.co.uk>
  6. Date: 23 Jan 93 15:36:51 GMT
  7. References: <9301201500.AA20662@anon.penet.fi>
  8. Sender: news@micrognosis.co.uk
  9. Organization: Micrognosis, a division of CSK(UK) Ltd
  10. Lines: 40
  11.  
  12. In article <9301201500.AA20662@anon.penet.fi>, an6034@anon.penet.FI writes:
  13. |> cc example_1.c
  14. |>     void main(void){ /* begin main */
  15. |> %CC-W-INVMAINRETVAL, Return value of main function is not an integer type.
  16. |>         At line number 8 in $DISK:EXAMPLE_1.C;24.
  17.  
  18. |> So am I missing a compiler switch that will make it all ok??
  19.  
  20. The short answer is ... no, this is not valid C code so you must fix it.
  21. main *must* return an 'int'.
  22.  
  23. The long answer is ... both K&R I and ANSI X3.159-1989 define main as a
  24. function returning 'int' and taking two arguments (an 'int' and an 'array of
  25. pointer to char'). ANSI also allows main to be defined as taking a 'void'
  26. argument list. Neither allows main to be a 'void' function since its return
  27. value may be used by the host system.
  28.  
  29. The ANSI standard states that a return from the initial call to main is
  30. equivalent to calling exit() with the argument set to the value returned to
  31. the caller of main. I cannot find an equivalent statement in K&R (unless
  32. you count the ambiguous reference to 'return value' in section 7.7) but I
  33. believe that this was codification of existing practice.
  34.  
  35. |> I have looked up the error message but it doesn't mean a thing to me.
  36.  
  37. In this case the second part of the explanation applies - "change the return
  38. value specification to one of the integer types". The first part is a
  39. warning about the following mistake ...
  40.  
  41. struct foo {
  42.     int    bar;
  43.     }
  44.  
  45. main(void) {}
  46.  
  47. Hope this helps, Neil (who is a little puzzled by the recent burst of
  48. message from anon.penet.fi).
  49. -- 
  50.  Phone: +44 71 815 5283  E-mail: nreadwin@micrognosis.co.uk
  51.  Anything is a cause for sorrow that my mind or body has made
  52.