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]

malloc attributes and realloc


Can __attribute__((__malloc__)) safely be used on realloc-type functions?  
glibc's <stdlib.h> has

extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;

while libiberty.h has

/* Reallocate memory without fail.  This works like xmalloc.  Note,
   realloc type functions are not suitable for attribute malloc since
   they may return the same address across multiple calls. */

extern PTR xrealloc PARAMS ((PTR, size_t));

- which is correct?  (Although the same value can be returned by realloc,
the program can't compare the values as values without undefined behavior,
only as bit patterns - and using them as bit patterns (a) involves taking
the address of one of the pointers involved (possibly inhibiting
optimization that way), (b) gets into the territory of DR#260.)

-- 
Joseph S. Myers
jsm@polyomino.org.uk


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