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


Hi Nathanael,

> Is there a known workaround if the comparison of dead pointers may
> be optimized out of existence?
> [[...]]
> If that worked, I wouldn't really complain.

Your workaround works, modulo segmented architectures.  May
the 8[123]86-es rest in peace.  (I know there are others, too.
Let them all rot. ;)  Anyway, the problem is not you (or me)
going forward.  It is my old code and my day to day colleagues.

> If there was another simpler workaround (like declaring p volatile or
> something) that would be even better.

A cast ought to ensure the segment piece of the address doesn't
wind up in a register that would fault.

Consider this:  I do work in a professional organization.  Nonetheless,
I was requested to cite chapter and verse as to why struct X had
to have 64 bit alignment on a 64 bit platform:

  union  Y { void* ptr; char ch[8]; };
  struct X { union Y uptr; char str[32]; };

>From there, I have to explain why it is correct for programs that
work on Solaris, AIX, HP/UX, and even Linux today suddenly start failing
on Linux?  No, thanks.  I'd rather explain why we need a commercial
C compiler (or libc?) on Linux, actually.  Bottom line:  realloc needs
to not have the malloc attribute and the standardized definition should
be changed to so state explicitly.

Yes, optimization is very important.  So are compatibility and obviousness
of interfaces.


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