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


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))


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