This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


Gabriel Dos Reis <gdr@integrable-solutions.net> writes:

> Robert Dewar <dewar@gnat.com> writes:
>
> | Gabriel Dos Reis wrote:
> | 
> | > No, I'm saying that the test
> | >     if (*p != 'a')
> | > cannot not be "skipped" (or turned into true) because there might be
> | > a
> | > data there that actually is an 'a'.
> | 
> | So what?
>
> So, it follows what I wrote:  The transformation is not valid in general.

I think you misunderstood the transformation.

  if (*p != 'a') { arbitrary code }

certainly cannot be converted to

  { arbitrary code } 

where p is a pointer just returned from realloc - or malloc, for that
matter.  It *could* be done for a pointer just returned from calloc
but I don't think it's worth implementing, I doubt anyone does that.

However,

  if (*p != 'a') { *p = 'a'; }

*can* validly be converted to

  { *p = 'a'; }

as long as p is known not to point to read-only memory, which *is* a
property of all pointers returned by realloc.  It's just not always an
optimization.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]