home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ukma!asuvax!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
- From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
- Subject: Re: Is this ANSI C?
- Message-ID: <1992Nov9.190607.3156@mksol.dseg.ti.com>
- Keywords: A bet
- Organization: Texas Instruments Inc
- References: <1dhkrtINNj99@duvel.cs.ubc.ca>
- Date: Mon, 9 Nov 1992 19:06:07 GMT
- Lines: 35
-
- In <1dhkrtINNj99@duvel.cs.ubc.ca> hassan@cs.ubc.ca (Moustafa Hassan) writes:
-
- >#include <stdio.h>
- >void main(void)
- >{
- > printf("hello world\n");
- >}
-
- >To settle a dispute, would someone please tell me whether the above
- >is ANSI C. I claim that 'main' (according to the pure ANSI standard)
- >must return an integer value, but nonetheless, some non-purists claim
- >that the above is ANSI. Please do not respond via email; I want
- >my opponent (8^) to be able to see all the messages.
-
- Main must return a value to the invocation environment which is of
- type int (in other words, you are correct). Consider that the startup
- code 'expects' an integer to come back from your main routine (unless
- you go in and edit the startup code). On many environments, it won't
- matter if you change it to 'void' IN THAT ENVIRONMENT. If you ever
- move the code it may matter very much indeed. And in some
- environments, things will die an ugly death at the end of your program
- because the startup code popped something off the stack (assuming a
- stack) or 'retrieved' a return value in some way and that return
- valued doesn't exist.
-
- The CALLED code (in this case, main) can elect to simply ignore
- arguments that are there (argc, argv), but you have no control over
- the environment you are called from. Therefore, you should always
- explicitly return an integer to the environment from main().
-
- --
- "Insisting on perfect safety is for people who don't have the balls to live
- in the real world." -- Mary Shafer, NASA Ames Dryden
- ------------------------------------------------------------------------------
- Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
-