Needless pointer-casts in C

前端 未结 12 726
刺人心
刺人心 2020-12-09 10:05

I got a comment to my answer on this thread:

Malloc inside a function call appears to be getting freed on return?

In short I had code like this:



        
12条回答
  •  盖世英雄少女心
    2020-12-09 10:49

    One possible error could (depending on this is whether what you really want or not) be mallocing with one size scale, and assigning to a pointer of a different type. E.g.,

    int *temp = (int *)malloc(sizeof(double));
    

    There may be cases where you want to do this, but I suspect that they are rare.

提交回复
热议问题