Thread overview | |||||
---|---|---|---|---|---|
|
March 03, 2008 const strings (D1.0) | ||||
---|---|---|---|---|
| ||||
Is this correct behavior? import std.stdio; import std.string; const MM_REAL_STR = "real"; const MM_INT_STR = "integer"; void main() { writefln(toString(MM_REAL_STR.ptr)); // --> prints "realinteger" } I thought all literal strings were supposed to be zero terminated. That doesn't go for const strings? --bb |
March 03, 2008 Re: const strings (D1.0) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | On Mon, 03 Mar 2008 18:27:12 +0900, Bill Baxter wrote: > Is this correct behavior? > > import std.stdio; > import std.string; > > const MM_REAL_STR = "real"; > const MM_INT_STR = "integer"; > > void main() > { > writefln(toString(MM_REAL_STR.ptr)); // --> prints "realinteger" > } > > I thought all literal strings were supposed to be zero terminated. That doesn't go for const strings? The problem is that these are NOT strings, but fixed length character literals, and those beasties don't have trailing zeros. Try this instead ... const string MM_REAL_STR = "real"; const string MM_INT_STR = "integer"; -- Derek Parnell Melbourne, Australia skype: derek.j.parnell |
March 03, 2008 Re: const strings (D1.0) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Mon, 03 Mar 2008 18:27:12 +0900, Bill Baxter wrote:
>
>> Is this correct behavior?
>>
>> import std.stdio;
>> import std.string;
>>
>> const MM_REAL_STR = "real";
>> const MM_INT_STR = "integer";
>>
>> void main()
>> {
>> writefln(toString(MM_REAL_STR.ptr)); // --> prints "realinteger"
>> }
>>
>> I thought all literal strings were supposed to be zero terminated.
>> That doesn't go for const strings?
>
> The problem is that these are NOT strings, but fixed length character
> literals, and those beasties don't have trailing zeros.
>
> Try this instead ...
>
> const string MM_REAL_STR = "real";
> const string MM_INT_STR = "integer";
>
Ooohhh. Great. That works. Thanks a lot.
--bb
|
Copyright © 1999-2021 by the D Language Foundation