tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Re: malloc(0)


From: postmaster
Subject: Re: [Tinycc-devel] Re: malloc(0)
Date: Mon, 23 Sep 2002 04:12:05 -0400 (EDT)

_____________________________
Ce message n'a pu être acheminé au
destinataire suivant : Bansard Stephane
en raison des difficultés liées à son courrier
électronique à l'Université de Montréal.
Votre message lui sera AUTOMATIQUEMENT acheminé dès.
que son courrier sera à nouveau fonctionnel.

Veuillez S.V.P. NE PAS lui retransmettre votre message.

En cas d'urgence, utiliser un autre moyen pour 
rejoindre votre destinataire.

rfc821:ERROR:452 Mailbox full
_____________________________
 
Hello folks!

Here comes one of my favorites: libc behaviour at the limits!

- ANSI C 1990 does not specify precisely what the semantics of malloc(0)
  it only says that free(NULL) is legitimate, and realloc(ptr,0) should free 
ptr.
- a quick note here on free(NULL): whenever you implement a wrapper on 
malloc/free
  make it adhere to this convention, it is very useful and becomes quite 
natural;
  I only test for NULL ptr before calling free() in cases where the function 
call
  would be too costly, a rare occasion.  As a matter of fact, very few C++ 
addicts
  know that its perfectly fine to 'delete' a NULL pointer.
- ISO/IEC 9899:1999 is more specific on the malloc(0) issue: section 7.20.3 
pg 324
  read: "if the size of the space request is zero, the behaviour is 
implementation-
  defined: either a null pointer is returned, or the behaviour is as the 
size
  were some nonzero value, except that the returned pointer shall not be 
used
  to access an object.
- tcc returns non NULL for malloc(0) because it allocates 1 more byte than
  requested to ensure that malloc'd areas are never contiguous.  This is 
needed
  for bound checking.  ISO reads in section 7.20.3 that each successful 
allocation
  shall yield a pointer to an object disjoint from any other object, yet 
that
  order and contiguity of storage is unspecified.

Conclusion: do not rely on implementation defined behaviour. Both glibc and 
ulibc
are OK on this issue, TCC internal libc can implement one or the other, 
preferably
glibc's, but not necessarily.

There are a lot of small details like these to polish in the C language,
keep contributing to tcc by testing it to the limits!

Chqrlie.

___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx



_______________________________________________
Tinycc-devel mailing list
address@hidden
http://mail.freesoftware.fsf.org/mailman/listinfo/tinycc-devel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]