Re: length of an array using sizeof() - problem
From: Peter Nilsson (airia_at_acay.com.au)
Date: 01/27/04
- Next message: Holger Hasselbach: "Re: why is casting malloc a bad thing?"
- Previous message: Christian Bau: "Re: strncmp performance"
- In reply to: Richard Bos: "Re: length of an array using sizeof() - problem"
- Next in thread: Lew Pitcher: "Re: length of an array using sizeof() - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 27 Jan 2004 20:17:19 +1100
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message
news:4014e5d1.265393796@news.individual.net...
> donLouis <papaindia@earthlink.net> wrote:
> > On Sat, 24 Jan 2004 14:00:57 +0000
> > Mark McIntyre <markmcintyre@spamcop.net> wrote:
> > > On Sat, 24 Jan 2004 01:23:53 GMT, in comp.lang.c , donLouis
> > > <papaindia@earthlink.net> wrote:
> > > >On Fri, 23 Jan 2004 09:47:20 -0500
> > > >Lew Pitcher <Lew.Pitcher@td.com> wrote:
> > > >
> > > >> > printf("output element number: %d = %f\n", i+1, s_out[i]);
> > > >> > }
> > > >> >
> > > >>
> > > >> Unless you are compiling with a C99-compliant compiler, you are
obliged to
> > > >> return an int value here. Please do so.
> > > >
> > > >Although I wouldn't omit the return, it isn't required.
> > >
> > > In fact, as Lew said, it is, unless you have a C99 compiler.
> >
> > If I understand this correctly, by omitting the return on a C89
> > program, the exit status of the program is undefined, but the
> > program itself is fine.
>
> Nope. Returning anything except 0, EXIT_SUCCESS or EXIT FAILURE makes
> the program defined, but its exit status undefined. _Not_ returning
> anything at all makes the program undefined;
Chapter and verse, please.
AFAIK, the C90 language specification says _nothing_ about what the host
does with an exit status, defined or otherwise.
> it could, for example,
> confuse the startup code into crashing, much as declaring main() to
> return a float could.
My draft C89 copy says...
2.1.2.2 Hosted environment
...
"Program termination"
A return from the initial call to the main function is equivalent
to calling the exit function with the value returned by the main
function as its argument. If the main function executes a return that
specifies no value, the termination status returned to the host
environment is undefined.
3.6.6.4 The return statement
...
If a return statement without an expression is executed, and the
value of the function call is used by the caller, the behavior is
undefined. Reaching the } that terminates a function is equivalent to
executing a return statement without an expression.
If the first sentence of "Program termination" were the only clause, then
you would have a case because of 3.6.6.4, but it _explicitly_ goes on to
state that a termination status _is_ returned to the host, albeit an
undefined one.
-- Peter
- Next message: Holger Hasselbach: "Re: why is casting malloc a bad thing?"
- Previous message: Christian Bau: "Re: strncmp performance"
- In reply to: Richard Bos: "Re: length of an array using sizeof() - problem"
- Next in thread: Lew Pitcher: "Re: length of an array using sizeof() - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|