bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: small header change to correct an unnecessary compiler warning


From: agthorr
Subject: Re: small header change to correct an unnecessary compiler warning
Date: Thu, 12 Jul 2001 09:17:11 -0400
User-agent: Mutt/1.2.5i

On Thu, Jul 12, 2001 at 07:07:18AM +0200, Andreas Jaeger wrote:
> 
> It's not legal code - strtol assigns a value to foo afterwards and
> with the restrict you explicitly say that those two do not alias each
> other.

As I parse it, they do not alias each other.  strtol() assigns a value
to foo, but not to *foo.  Since foo exists in the caller's stack space
and not strtol()'s, there is no danger of nptr and endptr clobbering
one another within strtol().

>From ISO C99 (circa page 126):

------------------------------------------------------------------------
          In other words, E depends on the value of P itself rather
          than on the value  of  an  object  referenced  indirectly
          through  P.   For  example, if identifier p has type (int
          **restrict), then the pointer expressions p and  p+1  are
          based  on  the restricted pointer object designated by p,
          but the pointer expressions *p and p[1] are not.
------------------------------------------------------------------------

> Your changes are therefore wrong - and we can't change it since
> standards (ISO C99) mandate the prototype exactly as we have it.

hmm... I confess that I haven't read all of ISO C99.  Could you point
me to the section that states that prototypes must be exactly as
specified in the standard?

Based on the brief Conformance section near the beginning, it looks to
me like the implementation must merely work properly for all
strictly-conforming C99 programs.  My suggested change would not break
this.  (assuming I am right about the use of __restrict ;-))

Respectfully,
-- Agthorr

------------------------------------------------------------------------
> Agthorr <address@hidden> writes:
> 
> > I'm running GNU libc version 2.2.3.
> > 
> > I recently noticed that the function strtol() is declared as follows:
> > 
> > extern long int strtol (__const char *__restrict __nptr,
> >                         char **__restrict __endptr, int __base) __THROW;
> > 
> > This causes a warning to be generated unnecessarily for the following
> > perfectly legimate code:
> > 
> > ------------------------------------------------------------------------
> > #include <stdlib.h>
> > 
> > int main(void) {
> >         char bloop[] = "123";
> >         const char *foo = bloop;
> > 
> >         strtol (foo, &foo, 0);
> > 
> >         return 0;
> >}          
> > ------------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]