init.c revision 1.5
11.5Srillig/* $NetBSD: init.c,v 1.5 2021/12/17 10:33:23 rillig Exp $ */ 21.1Srillig# 3 "init.c" 31.1Srillig 41.1Srillig/* 51.1Srillig * Tests for initialization. 61.1Srillig * 71.1Srillig * C99 6.7.8 81.1Srillig */ 91.1Srillig 101.1Srillig/* 111.1Srillig * C99 does not allow empty initializer braces syntactically. 121.1Srillig * Lint allows this syntactically, it just complains if the resulting 131.1Srillig * object is empty. 141.1Srillig */ 151.1Srillig/* expect+1: error: empty array declaration: empty_array_with_initializer [190] */ 161.1Srilligdouble empty_array_with_initializer[] = {}; 171.1Srilligdouble array_with_empty_initializer[3] = {}; 181.1Srillig 191.1Srillig/* 201.1Srillig * C99 does not allow empty initializer braces syntactically. 211.1Srillig */ 221.1Srilligstruct { 231.1Srillig int member; 241.1Srillig} empty_struct_initializer = {}; 251.2Srillig 261.2Srillig 271.2Srilligtypedef struct { 281.2Srillig const char *key; 291.2Srillig int n; 301.2Srillig} histogram_entry; 311.2Srillig 321.2Srillig/* 331.2Srillig * The C standards allow omitting braces around the structural levels. For 341.2Srillig * human readers, it is usually clearer to include them. 351.2Srillig * 361.2Srillig * Seen in external/ibm-public/postfix/dist/src/util/dict.c(624). 371.3Srillig * 381.5Srillig * TODO: Properly handle this situation; as of init.c 1.214 from 2021-12-17, 391.3Srillig * the below initialization sets in->in_err but shouldn't. 401.2Srillig */ 411.2Srilligconst histogram_entry hgr[] = { 421.2Srillig "odd", 5, 431.2Srillig "even", 5, 441.2Srillig}; 451.4Srillig 461.4Srillig 471.5Srillig/* 481.5Srillig * Initialization with fewer braces than usual, must still be accepted. 491.5Srillig * 501.5Srillig * TODO: Properly handle this situation; as of init.c 1.214 from 2021-12-17, 511.5Srillig * the below initialization sets in->in_err but shouldn't. 521.5Srillig */ 531.4Srilligstruct { 541.4Srillig int x, y; 551.4Srillig} points[] = { 561.4Srillig 0, 0, 3, 0, 0, 4, 3, 4 571.4Srillig}; 58