Passing static array to C variadic function
Daniel Gibson via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 22 06:28:27 PDT 2014
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.
ok, I didn't know about that hack.. which shouldn't have been used in
the first place :-P
So at least for strings it kinda makes sense.. and if strings are
considered char arrays (isn't there a proper string type in D2?) for
consistency it should be the same for other arrays.
Maybe at least the "Interfacing to C" and/or "C-style Variadic
Functions" documentation could supply a bit more information about how
to pass arrays and especially static arrays as vararg.
Anyway, thanks for the clarification!
Cheers,
Daniel
More information about the Digitalmars-d
mailing list