3 ms·
Tell me why struct* is incompatible with void* when it's such a standard case in C that you don't need a cast: struct foo *x = malloc(sizeof(struct foo));
by amiga386 5mo ago
Tell me why struct* is incompatible with void* when it's such a standard case in C that you don't need a cast:
struct foo *x = malloc(sizeof(struct foo)); /* malloc returns void* */
Or rather, tell me why the C11 standards committee decided to declare that struct* is incompatible with a void*
- tomp 5mo agook so Claude says I was wrong, it's more subtle. (1) you can cast between any pointer types (no UB - assuming they're aligned), but accessing memory through a wrongly-typed pointer is UB (2) the only exception is char*, which allows you a "byte view of memory" (3) calling a function through a pointer requires the parameter pointer types to be compatible, and none of these are: int*, struct foo *, void*, char*