This is the mail archive of the gcc-patches@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]

Re: Patch: malloc function attribute



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


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