libgloss/arm/libcfunc.c: alarm [PATCH]

Shaun Jackman
Thu Jul 14 19:45:00 GMT 2005

On 7/14/05, Nick Clifton <> wrote:
> Why are you making abort() call _exit() ?  What is wrong with using the
> SWI that is intended for this purpose ?
> This matters because the current implementation of _exit() ignores its
> argument and always performs a SWI with ADP_StoppedApplicationExit, so
> the user (or simulator) will never know that an abort has occurred.

I didn't notice that the RDI implementation behaves differently than
the RDP implementation of _exit, which does pass its argument on to
the swi.  In the RDP case, calling _exit explicitly makes it more
apparent that abort is implemented in terms of _exit.

> > +int __attribute__((weak))
> > +pause (void)
> >  {
> > +     return errno = ENOSYS, -1;
> >  }
> Ugg!  There is no need for clever coding here.  Use two statements not a
> comma, it is much clearer that way.  (There are several places where
> this applies).

I think of setting errno and returning -1 as a single conceptual
operation, which is why I like the look of the above idiom, but fair

> > +int __attribute__((weak))
> > +_raise (int sig)
> >  {
> > -  return;
> > +  (void)sig;
> > +  return errno = ENOSYS, -1;
> >  }
> "(void)sig" ?  What on earth ?  If you want to avoid a compile time
> warning about an unused parameter, then why not just have "sig = sig" as
> is used in _exit() for example.  I am not even sure if "(void)sig" is
> portable or even valid C.

Casting to (void) is legal C and is a common idiom [1] to explicitly
point out that the coder does not intend to use the value of any
particular expression, not just an unused identifier. For example, in
libgloss/rs6000/sol-cfuncs.c the author has written...
  (void) write (2, msg, p-msg);
... and by casting to (void) has stated explicitly that he or she
hasn't simply forgotten to check the return value of write(2) for an
error, but that the correct response to an error in this case is to
ignore it.

I much prefer (void)identifier; to identifier=identifier; because the
former is expressing exactly what I mean, "I do not care what the
value of the following expression is." whereas the latter looks like a
potentially meaningful operation.


[1] The cast to void is referred to in the apt and humorous "Ten
Commandments of the C Programmer (Annotated Edition)"

More information about the Newlib mailing list