[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: C Programming

On Sun, May 09, 2004 at 08:34:28AM -0500, Jeff Vian wrote:
> Please explain why main cannot be of type void.

[ snip ]

> If you can provide *definitive documentation* of your statement that
> his teaching is wrong in the requirements for function main() I would
> like to see it.

>From the comp.lang.c FAQ at http://www.eskimo.com/~scs/C-faq/q11.12.html

  Question 11.12

  Can I declare main as void, to shut off these annoying ``main returns
  no value'' messages?

  No. main must be declared as returning an int, and as taking either
  zero or two arguments, of the appropriate types. If you're calling
  exit() but still getting warnings, you may have to insert a redundant
  return statement (or use some kind of ``not reached'' directive, if

  Declaring a function as void does not merely shut off or rearrange
  warnings: it may also result in a different function call/return
  sequence, incompatible with what the caller (in main's case, the C run-
  time startup code) expects.

  (Note that this discussion of main pertains only to ``hosted''
  implementations; none of it applies to ``freestanding''
  implementations, which may not even have main. However, freestanding
  implementations are comparatively rare, and if you're using one, you
  probably know it. If you've never heard of the distinction, you're
  probably using a hosted implementation, and the above rules apply.)

  References: ANSI Sec., Sec. F.5.1
  ISO Sec., Sec. G.5.1
  H&S Sec. 20.1 p. 416
  CT&P Sec. 3.10 pp. 50-51 



  This is the definition of my life

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]