Skip to content

C sizeof(struct) - bad order of evaluation #595

@h0nzZik

Description

@h0nzZik

The program

int main() {
        return sizeof(struct S{int x;}) + sizeof(struct S);
}

fails to compile, with the error message

empty0.c:2:2: warning: Trying to compute sizeof of an incomplete or function type. (Constraint violation)

However, if we swap the operands of +, the program compiles (with -fno-native-compilation):

int main() {
        return sizeof(struct S) + sizeof(struct S{int x;});
}

I guess that the problem is that the right side of + is evaluated first. For -,*, and /, the order of evaluation seem to be right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions