简体   繁体   中英

gcc: how is “implementation-defined” malloc(0) defined?

C standard (eg C99) tells that malloc(0) returns "a null pointer or a unique pointer that can be successfully passed to free()". Which of the two, is implementation-defined . (This has been asked on StackOverflow many times, eg 1 , 2 , 3 , 4 .)

My question is: how does GCC define it?

GCC doesn't define it at all. GCC uses the malloc() implementation provided by the standard library. On OS X this will be libSystem, on Linux this will usually be glibc or eglibc, etc. These libraries are open source, so you can browse the source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM