What is the difference between xmalloc and malloc?

前端 未结 6 1177
萌比男神i
萌比男神i 2021-01-31 13:57

What is the difference between xmalloc() and malloc() for memory allocation?
Is there any pro of using xmalloc()?

6条回答
  •  醉酒成梦
    2021-01-31 14:55

    xmalloc() is a non-standard function that has the motto succeed or die. If it fails to allocate memory, it will terminate your program and print an error message to stderr.

    The allocation itself is no different; only the behaviour in the case that no memory could be allocated is different.

    Use malloc(), since it's more friendly and standard.

提交回复
热议问题