Authors: Aaron Ballman
Date: 2026-04-22
Submitted against: C23
Status: Open
Consider the following code:
#include <stdio.h>
struct {
char str[16];
} hello = {
"hello world",
.str[6] = 'W',
"ORLD"
};
int main(void) {
printf("hello.str = \"%s\"\n", hello.str);
printf("raw bytes: ");
for (int i = 0; i < 16; i++) {
printf("%d ", (unsigned char)hello.str[i]);
}
printf("\n");
return 0;
}
What should this program output?
char * to char which
results in truncation (with assigning "ORLD" to str[7] presumably)"hello WORLD""ORLD""hello Wl@@"Which, if any, of these behaviors is the expected one? I can see a reading of the standard that allows for any of the first three behaviors depending on how you interpret C23 6.7.11p18-19.