Why does the compiler complain when I do not cast the result of malloc?

前端 未结 2 434
礼貌的吻别
礼貌的吻别 2021-01-15 09:47

I am inspecting code that does not require explicitly casting result of malloc call but whenever I attempt to do this, the compiler throws an error.

i.e.

<         


        
2条回答
  •  无人共我
    2021-01-15 10:29

    This happens if you use C++ compiler instead of C compiler. As C++ requires explicit casting. The problem is not just with (un)casting malloc result, but any void pointer to other pointer.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题