In addition to the points already discussed when exactly space is freed up and whether the construction is supported at all, the following also exists:
- In the case of
alloca bytes has a pointer type. - In the case of
[] bytes has an array type.
The most noticeable difference is that sizeof(bytes) ; for a pointer, this is the size of the pointer ( sizeof(void *) ), while for an array, this is the size of the allocated space ( sizeof(char) * size , which = size for this case, since sizeof(char) = 1).
(In addition, in your example, the types of elements are different: the same thing, the first should be changed to char *bytes = alloca(size) .)
Kevin reid
source share