Passing static array to C variadic function

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 20 21:07:27 PDT 2014



"Daniel Gibson"  wrote in message news:lqh3vb$c2b$1 at digitalmars.com...

> * passing stuff to the function is done as C expects it (not done,
>    also: are there other cases than the static array one that are
>    different?)

Dynamic arrays.

D used to allow passing static and dynamic arrays to C varargs with no 
problems.  This lead to nasty segfaults, especially with this code:

printf("Hello %s\n", "segfault");

which looks perfectly valid in D but certainly isn't.  What you actually 
meant to pass is up to you to specify.  It would not make a lot of sense for 
C functions to have a different set of implicit conversion rules to other 
functions.

> * Disallowing template arguments (because how would I declare and call
>    that function in C?) (not done)

This is probably worth reporting, I doubt it works correctly.

> * /Maybe/ disallowing types as arguments/return types that are not
>    supported by C (D classes; not done)?
>    (OTOH, one the C side one could just handle them as void* and pass
>    instances around opaquely)

Yes, this is why they are not disallowed.  This is just too damn useful.

printf("Pointer: %p\n", new Class()); 



More information about the Digitalmars-d mailing list