136-block-inferred-string.c (585B)
1 /* Block-scope char[] with string-literal initializer: 2 * `char s[] = "hello";`. sizeof(s) must be 6 (5 chars + NUL), 3 * each byte must read back correctly, and an adjacent local 4 * declared after must NOT be clobbered. 5 */ 6 7 int main(int argc, char **argv) { 8 char s[] = "hello"; 9 int sentinel = 0xCAFE; 10 11 if (sizeof(s) != 6) return 1; 12 if (s[0] != 'h') return 2; 13 if (s[1] != 'e') return 3; 14 if (s[2] != 'l') return 4; 15 if (s[3] != 'l') return 5; 16 if (s[4] != 'o') return 6; 17 if (s[5] != 0) return 7; 18 if (sentinel != 0xCAFE) return 8; 19 return 0; 20 }