malloc

T

thibault volpert

Hi everybody.

I took a look to the faq at
<http://www.eskimo.com/~scs/C-faq/top.html>
but i did not find the answer to my question.

So here is the question : Is it legal to use malloc(size) with size==0
?
If so i would expect malloc() to return a NULL pointer, is it true ?

Thanks
 
T

thibault volpert

thibault said:
Hi everybody.

I took a look to the faq at
<http://www.eskimo.com/~scs/C-faq/top.html>
but i did not find the answer to my question.

So here is the question : Is it legal to use malloc(size) with size==0
?
If so i would expect malloc() to return a NULL pointer, is it true ?

Thanks

Sorry for beeing too prompt to post, i found the answer in the faq :

Question 11.26

What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

The ANSI/ISO Standard says that it may do either; the behavior is
implementation-defined (see question 11.33).

References: ANSI Sec. 4.10.3
ISO Sec. 7.10.3
PCS Sec. 16.1 p. 386
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top