RE: [sv-bc] Is string allowed to be assigned to any data type?

From: Rich, Dave <Dave_Rich_at_.....>
Date: Mon Jan 28 2008 - 16:31:26 PST
The section on the string data type says this:

"A single character of a string variable is of type byte."

So a[0] is not a string type. It is a byte which is a fixed-sized
integral type. The rules for bit-stream casting with a fixed sized type
and an unpacked type require that the source type have the exact number
of bits as the destination type. If that can be checked at compile time,
the compiler is free to do that. But if the source involves a dynamic
type, run-time might be the only time to perform that check.

a[0] = byte'(b);

would be valid only if b had exactly one character, and that check could
only be performed at run-time.

If you never want this to be an error, then use the streaming operator.

a[0] = {<<{b}};

The only wrinkle in this is whether a string is considered a packed or
unpacked type. It certainly doesn't qualify as a packed type.

Dave


> -----Original Message-----
> From: Surya Pratik Saha [mailto:spsaha@cal.interrasystems.com]
> Sent: Sunday, January 27, 2008 5:57 AM
> To: Rich, Dave
> Cc: sv-ec@eda.org; sv-bc@eda.org
> Subject: Re: [sv-bc] Is string allowed to be assigned to any data
type?
> 
> Hi Dave,
> I did not see anything in the LRM mentioning that restriction.
> 
> How do I impose a cast here?
> Is
> a[0] = byte'(b);
> valid assignment then?
> 
> Also without cast, will it be a run time error or compilation time
> error. LRM does not clearly say assigning integral type to a string
> variable without cast is run time error or compilation time error.
What
> is your comment on that?
> 
> Regards
> Surya
> 
> 
> 
> -------- Original Message --------
> Subject: Re:[sv-bc] Is string allowed to be assigned to any data type?
> From: Rich, Dave <Dave_Rich@mentor.com>
> To: Surya Pratik Saha <spsaha@cal.interrasystems.com>, sv-ec@eda.org,
> sv-bc@eda.org
> Date: Saturday, January 26, 2008 11:17:43 PM
> >
> > A single element of a string is a byte, which is an integral type.
> > It's not legal to assign a string to an integral type without a
cast.
> >
> > With a cast, b would have to be exactly one character, or you will
get
> > a run time error.
> >
> > Dave
> >
> >
------------------------------------------------------------------------
> >
> > *From:* owner-sv-bc@server.eda.org
[mailto:owner-sv-bc@server.eda.org]
> > *On Behalf Of *Surya Pratik Saha
> > *Sent:* Saturday, January 26, 2008 4:21 AM
> > *To:* sv-ec@server.eda.org; sv-bc@server.eda.org
> > *Subject:* [sv-bc] Is string allowed to be assigned to any data
type?
> >
> > Hi,
> > As per SV 1800 LRM:
> > *A string or a string literal can be assigned directly to a string
> > variable. Integral types can be assigned to a string variable, but
> > require a cast.
> > *
> > This imposes some restriction when LHS of an assignment is a string
> > type. But is any data type allowed to be LHS when RHS is a string. I
> > did not see anything in the LRM, though following e.g. is marked as
> > illegal:
> > *string b = "";
> > string a = {"Hi", b};
> > a[0] = b; // invalid, requires a cast*
> >
> > It is not at all clear why the assignment is invalid, how it can be
> > made valid by casting on which side. Most of the simulators pass the
> > case though. Is there any mantis or clarification for that?
> >
> > --
> > Regards
> > Surya
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by *MailScanner* <http://www.mailscanner.info/>,
and
> is
> > believed to be clean.
> 
> 
> 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Jan 28 16:31:55 2008

This archive was generated by hypermail 2.1.8 : Mon Jan 28 2008 - 16:32:21 PST