-
Notifications
You must be signed in to change notification settings - Fork 249
Closed
Description
#include <stdint.h>
#include <stdio.h>
union {
int8_t;
uint32_t c;
} toto = { 730 };
int main() {
printf("%d\n", toto.c);
return 0;
}
According to C17 6.7.9.17 "When no designations are present, subobjects of the current object are initialized in order according to the type of the current object: [...] the first named member of a union."
Accordingly, gcc considers that the initializer initializes c to 730. In contrast, CompCert considers that it initializes the unnamed field to 730, which gets truncated to 218. So it seems CompCert's behavior is incorrect.
I don't think this is something likely to show up in real code, except perhaps if the unnamed field is meant as some form of padding.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels