From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Date: Thu, 4 Dec 2008 13:33:34 +0100 From: Sape Mullender Message-ID: <5f37b0148ff579ae7660653961a9dde0@plan9.cs.bell-labs.com> In-Reply-To: <599f06db0812040426u435f5a9dx7c1c0209c333db53@mail.gmail.com> References: <599f06db0812040407g59ee4feejc79ce8ecdec30451@mail.gmail.com> <599f06db0812040426u435f5a9dx7c1c0209c333db53@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-puwlgrnwtfkvjwoxilyxgmhdvd" Subject: Re: [9fans] initialization of anonymous structs. Topicbox-Message-UUID: 58c33afe-ead4-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-puwlgrnwtfkvjwoxilyxgmhdvd Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit typedef struct A A; typedef struct B B; struct A { int a1; int a2; }; struct B { A; int b1; int b2; }; B bvar = { .B = { .a1 = 2, .b1 = 2, }, }; --upas-puwlgrnwtfkvjwoxilyxgmhdvd Content-Type: message/rfc822 Content-Disposition: inline Received: from gouda.swtch.com ([67.207.142.3]) by plan9; Thu Dec 4 07:29:00 EST 2008 Received: from localhost ([127.0.0.1] helo=gouda.swtch.com) by gouda.swtch.com with esmtp (Exim 4.67) (envelope-from <9fans-bounces@9fans.net>) id 1L8DIh-0000ed-Pr; Thu, 04 Dec 2008 12:27:23 +0000 Received: from mail-gx0-f16.google.com ([209.85.217.16]) by gouda.swtch.com with esmtp (Exim 4.67) (envelope-from ) id 1L8DId-0000eY-EI for 9fans@9fans.net; Thu, 04 Dec 2008 12:27:22 +0000 Received: by gxk9 with SMTP id 9so4213082gxk.0 for <9fans@9fans.net>; Thu, 04 Dec 2008 04:27:03 -0800 (PST) Received: by 10.150.97.19 with SMTP id u19mr21452408ybb.206.1228393615170; Thu, 04 Dec 2008 04:26:55 -0800 (PST) Received: by 10.151.117.9 with HTTP; Thu, 4 Dec 2008 04:26:55 -0800 (PST) Message-ID: <599f06db0812040426u435f5a9dx7c1c0209c333db53@mail.gmail.com> Date: Thu, 4 Dec 2008 13:26:55 +0100 From: "Gorka Guardiola" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@9fans.net> In-Reply-To: <599f06db0812040407g59ee4feejc79ce8ecdec30451@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <599f06db0812040407g59ee4feejc79ce8ecdec30451@mail.gmail.com> Subject: Re: [9fans] initialization of anonymous structs. X-BeenThere: 9fans@9fans.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.9fans.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: 9fans-bounces@9fans.net Errors-To: 9fans-bounces+9fans-local=plan9.bell-labs.com@9fans.net On Thu, Dec 4, 2008 at 1:07 PM, Gorka Guardiola wrote: > Say I have a couple of structs like: > > typedef struct A A; > typedef struct B B; > > struct A > { > int a1; > int a2; > }; > > struct B > { > A; > int b1; > int b2; > }; > > Now I want to declare a variable of kind B with parts initialized. Is > there anyway to initialize the A inside the B?. I have tried: > > B bvar = { > .a1 2 > .b1 2 > }; > There is a way, with a display, but I wanted to name the fields. This works: B bvar = { 0, 0, 0, 0 }; I guess I can always add comments. -- - curiosity sKilled the cat --upas-puwlgrnwtfkvjwoxilyxgmhdvd--