[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Re: malloc(0)
From: |
Rogelio M. Serrano Jr. |
Subject: |
Re: [Tinycc-devel] Re: malloc(0) |
Date: |
Mon, 23 Sep 2002 16:44:22 +0800 (PHT) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Well for now the tcc_malloc(0) will return NULL; TCC works fine for me
now.
Except for the uclibc linked TCC of course. Im still testing my TCC build
in a uclibc only system. It seems that there is a lot of glibc dependence
in TCC.
On Mon, 23 Sep 2002, Charlie Gordon wrote:
> 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
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9jtRuytnOHirK9T8RAjVVAJ4itDAX/2CVFCbzvTJLRPE+1AQYiwCeOXOr
mBQ2ynGjR2DudjdjmEArhTU=
=H9P1
-----END PGP SIGNATURE-----