Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

va_list with multiple types

Name: Anonymous 2010-07-24 1:23

i want to write soemthing like this:
a function which will print various types of arguments.
I tried to work with va_list, it doesn't work.
int main(){
write("this ",1.2," is ",'a',7," test");
}
should result in:
this 1.2 is a7 test

Name: Anonymous 2010-07-24 2:35

>>8
yes, if print is just void print(uintmax_t n){ printf("%" PRIuMAX "\n", n); }.
if you want type-specific behavior, you have to tell the function what types you're giving it. there's already an established way to do that, which >>3 showed you.
or, you could do this:
struct idiot_object{
  enum type { INT, FLOAT, STR };
  union value { uintmax_t i;
                unsigned char c;
                long double f;
                char *s; }}
...
struct idiot_object a = { .type = FLOAT, .value = { .f = 5.4 }},
                    b = { .type = STR,   .value = { .s = "text" }},
                    c = { .type = INT,   .value = { .i = 1 }},
                    d = { .type = FLOAT, .value = { .f = 5e200 }};

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List