Passing static array to C variadic function
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 22 07:05:09 PDT 2014
On Tuesday, 22 July 2014 at 13:28:27 UTC, Daniel Gibson wrote:
> Am 22.07.2014 11:01, schrieb Daniel Murphy:
>>
>> Old D code (from the 32-bit only days) used to do this
>> successfully:
>>
>> printf("Hello %.*s\n", "segfault");
>>
>> So it relied on both the length and pointer being passed.
>> Unfortunately
>> this was done quite a lot, so simply changing the rules so
>> string
>> literals get passed to C varargs as pointers would silently
>> (and
>> horribly) break this code.
> (isn't there a proper string type in D2?)
nope, it's just an ordinary slice (although the fact that it's a
slice of char does make it a bit special w.r.t. unicode)
The compiler doesn't even know about the name string, it's just
defined here:
https://github.com/D-Programming-Language/druntime/blob/master/src/object.di#L28
More information about the Digitalmars-d
mailing list