0

C standard (e.g. 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, e.g. 1, 2, 3, 4.)

My question is: how does GCC define it?

1
  • As whatever the C library on the target system provides? Commented Jan 14, 2015 at 16:31

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Dietrich: Thank you! bazaar.launchpad.net/~vcs-imports/glibc/master/view/head:/… says that "Even a request for zero bytes (i.e., malloc(0)) returns a pointer to something of the minimum allocatable size."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.