gcc_init_compound_literal.c revision 1.2
1/* $NetBSD: gcc_init_compound_literal.c,v 1.2 2021/04/17 20:57:18 rillig Exp $ */ 2# 3 "gcc_init_compound_literal.c" 3 4/* 5 * C99 says in 6.7.8p4: 6 * 7 * All the expressions in an initializer for an object that has static 8 * storage duration shall be constant expressions or string literals. 9 * 10 * The term "constant expression" is defined in C99 6.6, where 6.6p9 allows 11 * "constant expressions" in initializers to also be an "address constant". 12 * Using these address constants, it is possible to reference an unnamed 13 * object created by a compound literal (C99 6.5.2.5), using either an 14 * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1. 15 */ 16 17// Seen in sys/crypto/aes/aes_ccm.c. 18const struct { 19 const unsigned char *ctxt; 20} T = { 21 (void *)0, 22 (void *)0, /* expect: too many struct/union initializers */ 23// FIXME: lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC" failed 24// .ctxt = (const unsigned char[4]){ 25// 1, 2, 3, 4 26// }, 27}; 28 29struct node { 30 int num; 31 struct node *left; 32 struct node *right; 33}; 34 35/* 36 * Initial tree for representing the decisions in the classic number guessing 37 * game often used in teaching the basics of programming. 38 */ 39/* TODO: activate after fixing the assertion failure 40static const struct node guess = { 41 50, 42 &(struct node){ 43 25, 44 &(struct node){ 45 12, 46 (void *)0, 47 (void *)0, 48 }, 49 &(struct node){ 50 37, 51 (void *)0, 52 (void *)0, 53 }, 54 }, 55 (void *)0 56}; 57*/ 58