4 ms·
I wonder if this item, "Assignments between incompatible pointer types" includes what I understood is (was?) actually recommended practice in C - `int *c = mall
by simiones 3y ago
I wonder if this item, "Assignments between incompatible pointer types" includes what I understood is (was?) actually recommended practice in C - `int *c = malloc(sizeof(int))`. Has the preferred style changed, or is this only a problem for non-void pointer types (i.e. `float *p = &some_int`) ?
- quelsolaar 3y agoYou are right. void pointers can convert to any pointer type in C. That's why you don't need to cast malloc in C.
- cmovq 3y agoGCC will not warn with implicit void pointer conversions, I believe that’s explicitly allowed. It’s only when you have incompatible types like ‘float *y = (int *)x;’
- EPWN3D 3y agoI really prefer sizeof(*c) in that expression to protect against a badly-sized allocation of c's type changes.