Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 13, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Derek Parnell Wrote:
> You could try this simpler method ...
Oh. Slices! I didn't think of that. It should be just as efficient too, since these slices will not copy the contents.
As for your follow-up, I thought that
char abc[32];
would initialize abc to 32 zeroes automatically. Am I wrong?
|
August 13, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to C. Dunn | C. Dunn wrote: > As for your follow-up, I thought that > char abc[32]; > would initialize abc to 32 zeroes automatically. Am I wrong? chars are initialized to 0xff -- Oskar |
August 13, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | "Oskar Linde" <oskar.lindeREM@OVEgmail.com> wrote in message news:f9qcug$2sgj$1@digitalmars.com... > C. Dunn wrote: > >> As for your follow-up, I thought that >> char abc[32]; >> would initialize abc to 32 zeroes automatically. Am I wrong? > > chars are initialized to 0xff There are a few ways to get that initialized to 0 in the struct, tho: 1) Just write the initializer in the struct. struct S { char[32] abc = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; } Kind of ugly, but straightforward. 2) Typedef a zero-init char type. typedef char zchar = 0; struct S { zchar[32] abc; } You then might run into annoyances when converting between char and zchar. |
August 14, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote: > "Oskar Linde" <oskar.lindeREM@OVEgmail.com> wrote in message news:f9qcug$2sgj$1@digitalmars.com... >> C. Dunn wrote: >> >>> As for your follow-up, I thought that >>> char abc[32]; >>> would initialize abc to 32 zeroes automatically. Am I wrong? >> chars are initialized to 0xff > > There are a few ways to get that initialized to 0 in the struct, tho: > > 1) Just write the initializer in the struct. > > struct S > { > char[32] abc = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; > } > > Kind of ugly, but straightforward. > Ever since Issue 1268 was fixed in 1.017, you can just write: char[32] abc = 0; -- Remove ".doesnotlike.spam" from the mail address. |
August 14, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Deewiant | "Deewiant" <deewiant.doesnotlike.spam@gmail.com> wrote in message news:f9rjbi$1sav$1@digitalmars.com... > > Ever since Issue 1268 was fixed in 1.017, you can just write: > > char[32] abc = 0; > I always wished that that were possible, but never knew if it was legal :D |
August 14, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> "Deewiant" <deewiant.doesnotlike.spam@gmail.com> wrote in message news:f9rjbi$1sav$1@digitalmars.com...
>> Ever since Issue 1268 was fixed in 1.017, you can just write:
>>
>> char[32] abc = 0;
>>
>
> I always wished that that were possible, but never knew if it was legal :D
>
>
Oh it is, but there's no equivelant one-liner for dynamic arrays. Instead you have to:
auto var = new int[len];
var[] = 42;
Or using Cashew:
import cashew.utils.Array;
// ...
auto var = repeat(42, len);
Which is actually just a wrapper around the above example. It'd be nice if there were some way to specify an initializor for a dynamic array's elements in place, that didn't rely on using a typedef.
typedef int _MyInt42 = 42;
auto var = cast(int[]) new _MyInt42[len];
o_O
-- Chris Nicholson-Sauls
|
August 14, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls wrote:
> Jarrett Billingsley wrote:
>> "Deewiant" <deewiant.doesnotlike.spam@gmail.com> wrote in message news:f9rjbi$1sav$1@digitalmars.com...
>>> Ever since Issue 1268 was fixed in 1.017, you can just write:
>>>
>>> char[32] abc = 0;
>>>
>>
>> I always wished that that were possible, but never knew if it was legal :D
>>
>
> Oh it is, but there's no equivelant one-liner for dynamic arrays. Instead you have to:
>
> auto var = new int[len];
> var[] = 42;
>
> Or using Cashew:
>
> import cashew.utils.Array;
> // ...
> auto var = repeat(42, len);
>
> Which is actually just a wrapper around the above example. It'd be nice if there were some way to specify an initializor for a dynamic array's elements in place, that didn't rely on using a typedef.
>
> typedef int _MyInt42 = 42;
> auto var = cast(int[]) new _MyInt42[len];
>
> o_O
You gonna make that cashew available via dsss net any time soon? If not you mind if I do it?
--bb
|
August 14, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> Chris Nicholson-Sauls wrote:
>> Jarrett Billingsley wrote:
>>> "Deewiant" <deewiant.doesnotlike.spam@gmail.com> wrote in message news:f9rjbi$1sav$1@digitalmars.com...
>>>> Ever since Issue 1268 was fixed in 1.017, you can just write:
>>>>
>>>> char[32] abc = 0;
>>>>
>>>
>>> I always wished that that were possible, but never knew if it was legal :D
>>>
>>
>> Oh it is, but there's no equivelant one-liner for dynamic arrays. Instead you have to:
>>
>> auto var = new int[len];
>> var[] = 42;
>>
>> Or using Cashew:
>>
>> import cashew.utils.Array;
>> // ...
>> auto var = repeat(42, len);
>>
>> Which is actually just a wrapper around the above example. It'd be nice if there were some way to specify an initializor for a dynamic array's elements in place, that didn't rely on using a typedef.
>>
>> typedef int _MyInt42 = 42;
>> auto var = cast(int[]) new _MyInt42[len];
>>
>> o_O
>
> You gonna make that cashew available via dsss net any time soon? If not you mind if I do it?
>
> --bb
Well... I admit I don't actually use DSSS myself. (The shame, I know.) So if you want to do so, go ahead. I have a long list of to-do items for Cashew... should really get to work on it. (Like adding those nifty binutils.)
-- Chris Nicholson-Sauls
|
August 15, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls wrote: > Bill Baxter wrote: >> Chris Nicholson-Sauls wrote: >>> Jarrett Billingsley wrote: >>>> "Deewiant" <deewiant.doesnotlike.spam@gmail.com> wrote in message news:f9rjbi$1sav$1@digitalmars.com... >>>>> Ever since Issue 1268 was fixed in 1.017, you can just write: >>>>> >>>>> char[32] abc = 0; >>>>> >>>> >>>> I always wished that that were possible, but never knew if it was legal :D >>>> >>> >>> Oh it is, but there's no equivelant one-liner for dynamic arrays. Instead you have to: >>> >>> auto var = new int[len]; >>> var[] = 42; >>> >>> Or using Cashew: >>> >>> import cashew.utils.Array; >>> // ... >>> auto var = repeat(42, len); >>> >>> Which is actually just a wrapper around the above example. It'd be nice if there were some way to specify an initializor for a dynamic array's elements in place, that didn't rely on using a typedef. >>> >>> typedef int _MyInt42 = 42; >>> auto var = cast(int[]) new _MyInt42[len]; >>> >>> o_O >> >> You gonna make that cashew available via dsss net any time soon? If not you mind if I do it? >> >> --bb > > Well... I admit I don't actually use DSSS myself. (The shame, I know.) So if you want to do so, go ahead. I have a long list of to-do items for Cashew... should really get to work on it. (Like adding those nifty binutils.) > > -- Chris Nicholson-Sauls Well, I gave it a go, but cashew, seems to depend on mango. And "dsss net install mango" is failing, so I guess I give up for now. Here's the error: mango\net\util\cache\model\ICache.d(15): module IMessage cannot read file 'mango\net\cluster\model\IMessage.d' ICache.d has this: private import mango.net.cluster.model.IMessage; but there is no mango/net/cluster directory in the sources that dsss net is grabbing. --bb |
August 15, 2007 Re: Biggest problems w/ D - strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | Chris Nicholson-Sauls Wrote:
> >> Ever since Issue 1268 was fixed in 1.017, you can just write: char[32] abc = 0;
> > I always wished that that were possible, but never knew if it was legal :D
> Oh it is, but there's no equivelant one-liner for dynamic arrays. Instead you have to:
>
> auto var = new int[len];
> var[] = 42;
If I cannot tell the "new int[]" expression what the initializer should be, then I would rather it not initialize at all. In the case above, it initializes twice!
|
Copyright © 1999-2021 by the D Language Foundation