This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
- From: neroden at twcny dot rr dot com (Nathanael Nerode)
- To: gcc at gcc dot gnu dot org
- Date: Fri, 2 Jan 2004 23:04:47 -0500
- Subject: Re: malloc attributes and realloc
Is there a known workaround if the comparison of dead pointers may
be optimized out of existence?
For instance, I might try this (if for instance memory addresses were
the same size as longs):
#include <stdlib.h>
int f(void) {
int* p;
int* q;
long old_addr;
long new_addr;
p = malloc(sizeof(int));
*p = 0;
old_addr = (long) p ;
q = realloc(p, sizeof(int));
new_addr = (long) q ;
if (old_addr == new_addr) {
*p = 1;
return *q;
}
return 0;
}
If that worked, I wouldn't really complain.
If there was another simpler workaround (like declaring p volatile or
something) that would be even better.
If there was simply *no* workaround, however, I would complain. There
has to be a reasonable way to compare the two in the case in which you
really want to and you know what you're doing; and it shouldn't involve
ordering the compiler not to optimize.
--
Nathanael Nerode <neroden at gcc.gnu.org>
http://home.twcny.rr.com/nerode/neroden/fdl.html