This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch: malloc function attribute
- To: vonbrand at inf dot utfsm dot cl
- Subject: Re: Patch: malloc function attribute
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Tue, 30 Nov 1999 11:05:41 -0800
- Cc: richard dot earnshaw at arm dot com, law at cygnus dot com, ghazi at caip dot rutgers dot edu, green at cygnus dot com, gcc-patches at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <199911301719.RAA06805@cam-mail1.cambridge.arm.com><199911301819.PAA06066@pincoya.inf.utfsm.cl>
This discussion has gone somewhat off track. The point is this:
o The standard specifically allows realloc to return the value
passed in. It doesn't say that you can't use the old variable
any more in that case. So, I'm quite confident that:
if ((y = realloc (x, 20)) == x)
y[2] = 6;
is perfectly legal ANSI/ISO C (modulo alignment, sizes of things,
etc.)
o As an author of portable code you must be conservative, and assume
that realloc always copies. You have no idea what realloc might
do on some platform not yet imagined.
o As a author of a compiler, you must be conservative, and assume
that realloc never copies. You have no idea what the user might
know about the realloc on their platform.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com