Re: [sv-bc] structure literal example in standard

From: Krishanu Debnath <krishanu_at_.....>
Date: Thu Jan 05 2006 - 03:46:16 PST
Shalom, I don't think I understand your point. Let me allow to elaborate this
example.

</code_begin>

struct {int X,Y,Z;} XYZ = '{3{1}};
typedef struct {int a,b[4];} ab_t;
int a,b,c;

ab_t obj;
ab_t obj1 [2:0];
ab_t obj2 [1:0][2:0];

</code_end>

Now if I want to assign value in obj.b array, I would write following array
literal.

obj.b = '{2{b,c}} // It should be okay because replication represents the
                   // whole dimension [*]

Now if I want to assign value in obj struct, I would extend it to ..

obj = '{a, '{2{b,c}}};

Now if I want to assign value in 1D array obj1, I would extend it to ..

obj1 = '{3{'{a, '{2{b,c}}}}};

So if we think obj2 is a 1D array of element obj1 of length 2.

obj2 = '{2{'{3{'{a, '{2{b,c}}}}}}};

Now does it match with the example shown in standard?
		

Bresticker, Shalom wrote:
> No.
> 
> You can see it described in 8.13.1, paragraph 2:
> 
> A syntax resembling multiple concatenations can be used in array
> assignment patterns as well. Each replication
> represents a single dimension.
> 
> unpackedbits = '{2 {y}} ; // same as '{y, y}
> int n[1:2][1:3] = '{2{'{3{y}}}}; // same as'{'{y,y,y},'{y,y,y}}

Yes perfectly valid example. But does the verse of 8.13.1p2 allow you to omit
the 'apostrophe' when you are replicating the value for most varying dimension?
If so then
int n[1:2][1:3] = '{2{3{y}}}} is valid?


Krishanu

[*] Sec 8.13.1p2 says ..
"A syntax resembling multiple concatenations can be used in array assignment
  patterns as well. Each replication represents a single dimension."

Does it also implies that you need to specify all the elements of that
dimension, if you are using replication operator?

e.g

int b;
int a[4] = '{4{b}}; // valid

but ,

int a[4] = '{b, b, 2{b}}; // is valid?

FYI, most of the tools reject the second initialization.

> 
> ==
> 
> You can also see it in assignment_pattern syntax (Syntax 8-2):
> 
> assignment_pattern ::=
>   '{ expression { , expression } }
> ...
> | '{ constant_expression { expression { , expression } } }
> 
> 
> Shalom
> 
>> -----Original Message-----
>> From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On
>> Behalf Of Krishanu Debnath
>> Sent: Thursday, January 05, 2006 12:16 PM
>> To: sv-bc@eda.org
>> Subject: [sv-bc] structure literal example in standard
>>
>> Hello,
>>
>> I am not sure about the correctness of the following example,
>> taken from
>> Sec 3.8 _Structure literals_.
>>
>> struct {int X,Y,Z;} XYZ = '{3{1}};
>> typedef struct {int a,b[4];} ab_t;
>> int a,b,c;
>> ab_t v1[1:0] [2:0];
>> v1 = '{2{'{3{a,'{2{b,c}}}}}};
>> /* expands to '{'{3{'{a,{2{b,c}}}}}, '{3{{a,'{2{b,c}}}}}} */
>> <rest snipped>
>>
>> Here the array literal assign to v1 is incorrect. I think
>> example
>> missed the "'" after struct literal. So it should be
>> '{2{'{3{'{a,'{2{b,c}}}}}}}. Similarly example missed the "'" in
>> second element of expansion.
>>
>> Can anyone please confirm?
>>
>> Thanks,
>> Krishanu
>>
Received on Thu Jan 5 03:44:34 2006

This archive was generated by hypermail 2.1.8 : Thu Jan 05 2006 - 03:46:44 PST