This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: Always provide exit() & friends prototypes.
- From: Sergei Organov <osv at javad dot com>
- To: ecos-patches at ecos dot sourceware dot org
- Cc: Jonathan Larmour <jifl at eCosCentric dot com>
- Date: Thu, 27 Sep 2007 21:13:45 +0400
- Subject: Re: Always provide exit() & friends prototypes.
- References: <87ir5w43y0.fsf@javad.com> <46FBCC7D.7090107@eCosCentric.com>
Jonathan Larmour <jifl@eCosCentric.com> writes:
> Sergei Organov wrote:
>> Hello,
>>
>> A short patch below ensures exit(), etc. prototypes are provided in
>> <stdlib.h> even when CYGINT_ISO_EXIT is undefined.
>>
>> For me it solves the problem that I don't wish to use libc_startup
>> package, but do use exit()/abort() routines in applications. So the
>> situation is that application itself provides implementation of those
>> functions, while their declarations are expected to be found in the
>> <stdlib.h>.
>
> Then you should add your own package and implement CYGINT_ISO_EXIT;
Even if I can't think of an implementation? A package that provides
empty or CYG_FAIL'ing exit()? Why?
> or declare them in your own application-specific header.
Not an option. Almost any C code on this planet expects to find exit()
declaration in the <stdlib.h>.
> Only OS definitions should go in <stdlib.h>.
The contents of <stdlib.h> is specified by the C standard, and exit() is
standard declaration that should be there in <stdlib.h> according to the
C standard. Currently (at some configuration options) eCos provides
non-standard <stdlib.h> and non-standard libc. I'd vote for standard
<stdlib.h> and non-standard libc (missing exit() definition) instead,
or, maybe, for exit() implementation that just calls CYG_FAIL. Though
I'd prefer to get error at link-time rather than at run-time.
>From practicality POV, it's more convenient to have all the standard
declarations there in <stdlib.h>, making existence/absence of their
implementation separate issue. What is the pain of having exit()
*declaration* at it's standard place in the <stdlib.h>?
>> For eCos source base itself, it solves the following problem. If one
>> configures eCos, e.g., like is shown below, and tries to compile with
>> rather recent GCC (v.3+; old versions of GCC happened to declare exit()
>> internally), she gets the following error:
>>
[...]
> That's a separate problem due to failing to take into account CDL
> dependencies. Fixed with the attached patch, checked in.
No, that's exactly this problem, -- see below.
[...]
> +#if CYGINT_ISO_EXIT
> exit(1000 + sig); // FIXME
> +#else
> + CYG_FAIL("Default signal handler called - no exit available");
> +#endif
Sorry, but this looks more like a work-around. In C, if you need exit(),
you call exit(), and if you need to call exit(), your include <stlib.h>,
period. If you still don't see the problem, there are actually hundreds
places that call exit() in the eCos "packages/" tree (I've counted
roughly 230). Are you going to check/fix all those as well?! That is
exactly the problem that I faced with in applications.
I think the CYG_FAIL() you have added rather belongs to the exit()
implementation, provided you prefer run-time checks (that besides are
off by default) over link-time checks.
--
Sergei.