Re: [sv-bc] 4.11 Structures and Unions

From: Greg Jaxon <Greg.Jaxon_at_.....>
Date: Fri Nov 04 2005 - 11:36:27 PST
Bresticker, Shalom wrote:
> 4.11 contains the following example:
> 
> typedef struct {
> 	int addr = 1 + constant;
> 	int crc;
> 	byte data [4] = '{4'{1}};
>   } packet1;
> 
> Is the second apostrophe in "  '{4'{1}}  " correct ?
> It does not seem consistent with other places in the standard, such as the following in 3.8:
> "struct {int X,Y,Z;} XYZ = '{3{1}};".

It is not correct.  Although both forms have been accepted by earlier
versions of SV, at best they mean different things.
I parse '{4'{1}} as a one-element pattern containing
a use of the non-standard size'{} syntax.  Experimental systems
which implemented that extension never converged on a useful
and obvious meaning.  A conforming system can issue a
syntax error here.

In order for the assignment pattern to contain four elements,
it should have been written as you suggest - as a "repeat".

The four "1"s are then cast to 8-bit bytes for assignment to
the four elements of "data".

> (In general, the rules about placement of the apostrophes and
>  curly brackets in literals do not seem clearly explained.)

The general rule is to use '{} wherever interpretation of
the contents of the curlies should correspond to the contextual
pattern of data types being constructed.  You'd use it when
you want the implicit (assignment) conversions to proceed
itemwise, treating the individual value expressions separately.

'{} is a shorthand for T'{} where the data type T comes from
the type propagation rules of the surrounding expression.
'{n{...}} and T'{n{...}} are "repeat construct" forms that
could equivalently be written as n conjoined copies of the
listed items.

I'm afraid that being definitive about what the feature means
and being directive about how to use the feature are somewhat
incompatible goals.  An LRM only needs to be definitive.

Greg Jaxon
Synopsys DCSV
Received on Fri Nov 4 11:36:42 2005

This archive was generated by hypermail 2.1.8 : Fri Nov 04 2005 - 11:37:50 PST