gcc_init_compound_literal.c revision 1.2
11.2Srillig/* $NetBSD: gcc_init_compound_literal.c,v 1.2 2021/04/17 20:57:18 rillig Exp $ */ 21.1Srillig# 3 "gcc_init_compound_literal.c" 31.1Srillig 41.1Srillig/* 51.1Srillig * C99 says in 6.7.8p4: 61.1Srillig * 71.1Srillig * All the expressions in an initializer for an object that has static 81.1Srillig * storage duration shall be constant expressions or string literals. 91.1Srillig * 101.2Srillig * The term "constant expression" is defined in C99 6.6, where 6.6p9 allows 111.2Srillig * "constant expressions" in initializers to also be an "address constant". 121.2Srillig * Using these address constants, it is possible to reference an unnamed 131.2Srillig * object created by a compound literal (C99 6.5.2.5), using either an 141.2Srillig * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1. 151.1Srillig */ 161.1Srillig 171.1Srillig// Seen in sys/crypto/aes/aes_ccm.c. 181.1Srilligconst struct { 191.1Srillig const unsigned char *ctxt; 201.1Srillig} T = { 211.1Srillig (void *)0, 221.1Srillig (void *)0, /* expect: too many struct/union initializers */ 231.1Srillig// FIXME: lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC" failed 241.1Srillig// .ctxt = (const unsigned char[4]){ 251.1Srillig// 1, 2, 3, 4 261.1Srillig// }, 271.1Srillig}; 281.2Srillig 291.2Srilligstruct node { 301.2Srillig int num; 311.2Srillig struct node *left; 321.2Srillig struct node *right; 331.2Srillig}; 341.2Srillig 351.2Srillig/* 361.2Srillig * Initial tree for representing the decisions in the classic number guessing 371.2Srillig * game often used in teaching the basics of programming. 381.2Srillig */ 391.2Srillig/* TODO: activate after fixing the assertion failure 401.2Srilligstatic const struct node guess = { 411.2Srillig 50, 421.2Srillig &(struct node){ 431.2Srillig 25, 441.2Srillig &(struct node){ 451.2Srillig 12, 461.2Srillig (void *)0, 471.2Srillig (void *)0, 481.2Srillig }, 491.2Srillig &(struct node){ 501.2Srillig 37, 511.2Srillig (void *)0, 521.2Srillig (void *)0, 531.2Srillig }, 541.2Srillig }, 551.2Srillig (void *)0 561.2Srillig}; 571.2Srillig*/ 58