This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
- From: Dan Nicolaescu <dann at ics dot uci dot edu>
- To: Chris Lattner <sabre at nondot dot org>
- Cc: Ian Lance Taylor <ian at wasabisystems dot com>, Robert Dewar <dewar at gnat dot com>, gcc at gcc dot gnu dot org, drow at mvista dot com, Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Sun, 04 Jan 2004 23:57:15 -0800
- Subject: Re: malloc attributes and realloc
- References: <Pine.LNX.4.44.0401042144110.32633-100000@nondot.org>
Chris Lattner <sabre@nondot.org> writes:
> > The pointers returned by an __attribute__ (malloc) function are not
> > considered distinct, see the pointer comparison example in the foobar
> > function below.
>
> > aaaa = myalloc_withattribute (SZ*sizeof(int));
> > bbbb = myalloc_withattribute (SZ*sizeof(int));
> >
> > /* this is not resolved at compile time at this time */
> > if (aaaa == bbbb)
> > return link_error ();
>
> Malloc can always return a null pointer. Thus the transformation you're
> looking for is not valid.
True.
Just change the test to be:
if (aaaa && (aaaa == bbbb))