Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is there any place to talk about language features? Date: Wed, 28 Sep 2016 14:19:32 -0700 Organization: None to speak of Lines: 35 Message-ID: References: <7f35f731-ab20-4bbe-a26e-8c3af67f6984@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="9333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183G4JVqzUlUCGbKragqkW8" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ThxIeW8GNMStBrHO8QUV/ja/3FI= sha1:uLT0V96uTYtU5bcFDtn2Tqj/eck= Xref: csiph.com comp.lang.c:94221 Thiago Adams writes: [...] > The feature I am thinking about is "default initializers" > > Today we can do: > > struct Point { int x; int y; }; > struct Point pt1 = { 1, 2 }; > > and this is useful when the initialization change by instance basis. > But, for some types the initialization is the same or it have common > initiation part for all instances. To avoid specify the common > initialization everywhere the solution is create a macro. > > struct Z { int type; }; > #define Z_INIT { 4 } > > struct Z z1 = Z_INIT; A minor point: this can be done without a macro: struct Z { int type; }; const struct Z Z_INIT = { 4 }; struct Z z1 = Z_INIT; [...] (comp.std.c might be a more appropriate place for this, but IMHO comp.lang.c is ok.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"