Change representation of dynamic arrays?

Walter Bright newshound1 at digitalmars.com
Sat Oct 20 00:38:06 PDT 2007


Anders F Björklund wrote:
> Walter Bright wrote:
> 
>>>> 1) Passing dynamic arrays to printf as in:
>>>>     printf("my string is %*.s\n", str);
>>>
>>> Hmmm, currently I use printf("foo %s\n",std.string.toStringz(bar))
>>> anyway, never tried what you're doing there. Did I miss something?
>>
>> printf("my string is %*.s\n", str.length, str.ptr);
>>
>> will be a little faster, because it doesn't need to allocate memory.
> 
> When I try this in C, it gives a warning about the "length" argument:
> field precision should have type 'int', but argument 2 has type 'size_t'
> 
> Wouldn't this warning apply to C too, when using the printf function ?
> I'm thinking it might need a cast(int) to work properly on 64-bit... ?

I think I'm not going to think about it and just deprecate it <g>.



More information about the Digitalmars-d mailing list