Skip to content

UB60

definition⚓︎

When the complete type is needed, an incomplete structure or union type is not completed in the same scope by another declaration of the tag that defines the content (6.7.2.3).

一个不完整的结构体或联合体类型在需要完整数据类型的地方被使用。

description⚓︎

此处的 incomplete structure or union type 指的应当是定义的结构体或联合体类型定义后未被补充完全便被调用。将此行为定义为 undefined behavior 的考虑有待补充,个人认为应当直接定为错误。

code⚓︎

#include<stdio.h>

struct A;

int main() {
    printf("%d", sizeof(struct A)); //undefined behavior
}