From mboxrd@z Thu Jan 1 00:00:00 1970 User-Agent: Cyrus-JMAP/3.1.6-329-gf4aae99-fmstable-20190329v1 Mime-Version: 1.0 Message-Id: <43a5572d-ea50-41a8-9897-9900f13c5a00@www.fastmail.com> In-Reply-To: References: Date: Mon, 1 Apr 2019 20:26:30 -0400 From: "Jeremy O'Brien" To: 9fans@9fans.net Content-Type: text/plain Subject: Re: [9fans] =?utf-8?q?Don=27t_Plan_9_C_compiler_initialize_the_rest_o?= =?utf-8?q?f_member_of_a=09struct=3F?= Topicbox-Message-UUID: f7ab570a-ead9-11e9-9d60-3106f5b1d025 On Mon, Apr 1, 2019, at 11:33, Kyohei Kadota wrote: > Hi, 9fans. I use 9legacy. > > About below program, I expected that flags field will initialize to > zero but the value of flags was a garbage, ex, "f8f7". > Is this expected? > > ``` > #include > > struct option { > int n; > char *s; > int flags; > }; > > int > main(void) > { > struct option opt = {1, "test"}; > printf("%d %s %x\n", opt.n, opt.s, opt.flags); > return 0; > } > ``` > > According to C99: "If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate." Stack variable == automatic storage duration. This appears to be correct behavior to me.