Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
gandalf013
· 9y ago · 0 comments
A very common idiom is "T
p = malloc(n
sizeof *p)". That only works if sizeof doesn't evaluate its arguments.
Comments
[–]
kazinator
9y ago
Why not? Suppose you have a C99 VLA object, and you want to malloc the equivalent amount of space. Couldn't you just do this:
int vla[nparam]; int *pcopyspace = malloc(sizeof vla);
Here
sizeof vla
is basically just
nparam
sizeof(int)
.
vla* is evaluated to the extent of calculating its run-time size.