Re: length of an array using sizeof() - problem

From: Peter Nilsson (airia_at_acay.com.au)
Date: 01/27/04


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


Relevant Pages

  • Re: Program termination and array deallocation
    ... Generally STOP means a "graceful" exit. ... user-specified cleanup (unless you use things like the at_exit stuff via ... specifically says that STOP causes a "normal termination"; ... That list of things that happen on normal termination doesn't happen to ...
    (comp.lang.fortran)
  • Re: Program without conditional Statements - Possible ?
    ... If the main function executes a return ... to get a clean compile from gcc -Wall, not because the program termination ... that only return one exit status: it contains as much information as no ... Dan Pop ...
    (comp.lang.c)
  • Re: Pointers
    ... An exit status of one is not portable. ... EXIT_SUCCESS for normal termination and EXIT_FAILURE for abnormal ones. ... which will call abort() if I was wrong, so that I can check what ...
    (comp.lang.c)
  • Re: Delivered signal info in exit status of a process?
    ... > order 7 bits of exit status of process should contain the signal ... directly, for example at the interpreter prompt, you'll ... effective exception handler at the time gives you. ... default exception handler for a script, but not a termination ...
    (comp.lang.python)
  • Re: java.lang.Win32Process.destroy() causes varying exitValue().
    ... is the only exit code that implies normal termination. ... program can get a shutdown event giving it a hint it should shutdown ...
    (comp.lang.java.help)