Date: Wed Feb 09 2005 - 12:10:08 PST
I looked at this more when I got home, and I thought about it more as well.
What 18.104.22.168 says is that leading "zeroes" are not printed.
It does not say anything about spaces.
If you look at parallel language in 22.214.171.124, it says that when printing
decimal values (i.e., numbers in decimal format),
"leading zeroes are suppressed and replaced by spaces.
In other radices, leading zeroes are always displayed."
"Other radices" means other integral numeric formats.
Strings are like decimal formats. The leading zeroes are not printed, but
space is left for them.
Only when you use a %0s format are the leading spaces omitted.
The most basic test, which I should have thought of earlier, is
reg[31:0] r = "" ;
$display ("%s", r, "cucu");
This will always give you " cucu" and never "cucu".
This shows that the zero bytes are printed as spaces.
But it's also true that the LRM does not say explicitly how \0 should be
printed and it should.
A harder question is how should other nonprinting characters be printed?
(a self-contradiction, of course)
And 126.96.36.199 explicitly says that leading NULs are not ignored:
"Padding can affect the results of comparison and concatenation operations".
On Wed, 9 Feb 2005, Neil Korpusik wrote:
> The results that Shalom is showing appear to be incorrect. The leading space
> appears to be inconsistent with what is stated in 188.8.131.52
> Even though the LRM doesn't explicitly state what character to print when
> a \0 is embedded within a string, it appears from 184.108.40.206 that the NUL
> character should not be treated like a string terminator, as shown in one of
> the outputs shown by Kausik.
> Printing a blank for an embedded NUL character seems to be the most appropriate
> thing to do. Ignoring leading NUL characters seems to be the most consistent
> with the rules for the comparison and concatenation operators (220.127.116.11).
> 18.104.22.168 String value padding and potential problems
> "When strings are assigned to variables, the values stored shall be padded
> on the left with zeros."
> "The comparison and cancatenation operators shall not distinguish between
> zeros resulting from padding and the original string characters (\0, ASCII
> 22.214.171.124 String format
> "No termination character or value is required at the end of a string, and
> leading zeros are never printed."
> Shalom Bresticker wrote:
> > The three simulators I have access to all print " s a", with leading space
> > before the "s".
> > Shalom
> > Kausik Datta wrote:
> >>I have one query related to use of escaped character in verilog.
> >>Let's take the following example:
> >>reg [31:0] a;
> >> a = "s\0a";
> >> #5 $diaplay("%s\n", a);
> >>Some tool print this one as "s a".
> >>and some tool print as "s"
> >>Which one is the correct output? LRM doesn't say anything about this.
> >>Kausik Datta
> > --
> > Shalom Bresticker Shalom.Bresticker @freescale.com
> > Design & Verification Methodology Tel: +972 9 9522268
> > Freescale Semiconductor Israel, Ltd. Fax: +972 9 9522890
> > POB 2208, Herzlia 46120, ISRAEL Cell: +972 50 5441478
> > [ ]Freescale Internal Use Only [ ]Freescale Confidential Proprietary
-- Shalom Bresticker Shalom.Bresticker @freescale.com Design & Verification Methodology Tel: +972 9 9522268 Freescale Semiconductor Israel, Ltd. Fax: +972 9 9522890 POB 2208, Herzlia 46120, ISRAEL Cell: +972 50 5441478 [ ]Freescale Internal Use Only [ ]Freescale Confidential Proprietary
This archive was generated by hypermail 2.1.4
: Wed Feb 09 2005 - 11:52:05 PST
sponsored by Boyd Technology, Inc.