3 ms·
> The file ends in `.c`, but the return type of `malloc` is cast to different pointer types I was taught this way, and lint used to complain if I didn't. Just
by ars 13y ago
> The file ends in `.c`, but the return type of `malloc` is cast to different pointer types
I was taught this way, and lint used to complain if I didn't. Just because it's legal not to cast doesn't also mean it's bad to cast.
- asveikau 13y agoAnd just because a tool tells you to do it ... I'll let you fill in the rest.
- Dylan16807 13y ago...you make the intent clear?
- asveikau 13y agoI get the impression from some of these responses that you folks would prefer: struct foo *bar = (struct foo*)malloc(sizeof(struct foo)); Over: struct foo *bar = malloc(sizeof(*bar)); I suppose the former is more clear by somebody's definition but I am going to continue to consider it somewhat ridiculous.
- mhogomchungu 13y agoI do something like this: char * buffer = ( char * )malloc( sizeof( char ) * 32 ) ; Why? because i like to look at my code written that way. If i code for somebody else's preference,i do it their way,if i code for my own consumption,i code it the way it pleases me.