Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将数组转换为 D 形式:
string[] arrayStr = [ "hi, "is fun", "use D programming" ];
我有一个 C 函数,它需要一个 C 可变参数:
void c_func( const char* format, ... );
我可以做:
foreach(str; arrayStr) func( str );
但这似乎是破解 C 可变参数,我宁愿直接转换为 C 可变参数,
我怎样才能做到这一点?
谢谢
AD 数组是一个由长度和指针组成的结构体。例如,您可以通过将 D 字符串格式化为“%.*s”将其传递给 printf。
因此,如果您将数组传递给 C 函数的可变参数,它将在其可变参数中找到一个 long int (length) 和一个 char[]* (ptr)。