Miscellaneous-NoEmptyStructsΒΆ

Structs/unions must not be empty

Required inputs: IR

Standard C requires structs and unions to contain at least one named member. This restriction does not apply in C++, nor in C with GNU extensions. However, these languages treat empty structs differently: sizeof(struct EmptyStruct { }) is 1 in C++, but 0 in GNU C. To avoid portability problems, empty structs should be avoided in C code.

Possible Messages

Key

Text

Severity

Disabled

empty_struct

Empty struct has undefined behavior

None

False

empty_union

Empty union has undefined behavior

None

False

struct_without_named

struct without named members has undefined behavior

None

False

union_without_named

union without named members has undefined behavior

None

False

Options