4 ms·
This flaw was pointed out while C99 was under review. The idea of changing sizeof to not be evaluated at compile-time did not sit well with a lot of people. Unf
by breadbox 9y ago
This flaw was pointed out while C99 was under review. The idea of changing sizeof to not be evaluated at compile-time did not sit well with a lot of people. Unfortunately, the alternative (sizeof not being usable with dynamic arrays) was clearly worse.
- bvda 9y agoDo you happen to know why that was perceived as worse? If I understand correctly the difference would be that you'd have to write (i * sizeof(char)) vs. (sizeof(char[i]))? Personally I'd even prefer the former.
- gandalf013 9y agoA very common idiom is "T p = malloc(n sizeof *p)". That only works if sizeof doesn't evaluate its arguments.
- kazinator 9y agoWhy 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.