<分区>
给定以下代码,它在 C 中是否合法? (C89、C99 等等?)
DATA_STRUCT *ptr;
ptr = malloc(sizeof(*ptr) + 400);
memset(ptr, 0, sizeof(*ptr)); // clearing only the structure itself (not the 400 additional bytes).
我知道 VLA 和 sizeof 在运行时被评估,但对于所有其他情况,它总是在编译时吗?
编辑: 从答案中我看到这可能是由于:
- 一个编译器错误
- 堆损坏
1 似乎不太可能,所以我倾向于 2。 无论哪种方式,这都需要进一步调查。