Re: what's this syntax?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Ian and Mike,

Thanks for the information.

Now I understand the following code is "the value of the member b of a compound literal which is initialized by a designated initializer". Is it correct ?

( ( union { int a; int b; }) { .a =7 }).b


Regards,

Mike







----- Original Message ----- From: "Ian Lance Taylor" <iant@xxxxxxxxxx>
To: "Michael Gong" <mwgong@xxxxxxxxxxxxxx>
Cc: "Michael Gong" <mwgong@xxxxxxxxxxxxxx>; <gcc-help@xxxxxxxxxxx>
Sent: Monday, December 11, 2006 3:09 PM
Subject: Re: what's this syntax?


"Michael Gong" <mwgong@xxxxxxxxxxxxxx> writes:

My question is how to interperate the code, since I don't understand
its syntax.

If it is a C99 code, what's the C99 feature for it ?

I'm sorry, I don't understand this question.  What kind of answer are
you looking for?

>> void foo() {
>>   if(
>>       ( __extension__
>>           (
>>               (
>>                   (
>>                       union {
>>                           int a;
>>                           int b;
>>                      }
>>                   ) { .a =7 }

This is a constructor expression.  The type is the anonymous union.
The value is the initializer expression, which in this case sets field
'a' to '7'.

>>               ) .b

This is a reference to field 'b' of the newly constructed union.  It
should be zero or garbage, I can't remember which.

>>            )
>>         ) == 7 ) {
>>               printf("abc\n");
>>     }else {
>>               printf("def\n");
>>    }
>> }

Ian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux