va_list ARM changes
Iain Buclaw
ibuclaw at ubuntu.com
Fri Aug 31 04:49:37 PDT 2012
On 31 August 2012 11:28, Johannes Pfau <nospam at example.com> wrote:
> I tested the changes as in revision
> 59f52c69d79b10c81913e837ecb14dad0c5fe264:
>
> I wasn't sure what exactly should be tested, this is the test case I
> used: http://dpaste.dzfl.pl/c362e632
> (not sure why it doesn't compile on dpaste, it works with my local dmd
> and gdc installation)
> This was the output:
> --------
> foo
> Test test 42
> -0.481002
> 42 Hello [10, 0, 0, 0, 200, 69, 246, 190, 0, 1]
> --------
>
Part of where you are going wrong is that 'va_arg (va_list, TypeInfo,
void*)' should only be used when the static type is indeterminable.
This is typically only for structs and classes. All basic types
should go through the normal va_arg template functions - these
actually get expanded intrinsically by the gcc backend and *do* the
right thing, even for your float example.
Now that is not to say that you can't use 'va_arg (va_list, TypeInfo,
void*)' for basic types, but you do need to be aware of type
promotions when it comes to va_args. :-)
Eg:
void main()
{
test2("", cast(float)3.45f, "TestTest"); // float is promoted to
double when passed as a vararg.
}
void test2(string input, ...)
{
double f;
string s;
va_list list;
va_start(list, input);
va_arg(list, typeid(typeof(f)), &f);
va_arg(list, typeid(typeof(s)), &s);
va_end(list);
writefln("%s %s", f, s);
}
And you'll see that test2() in your paste works.
--
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';
More information about the D.gnu
mailing list