Variable argument lists

Started by
1 comment, last by superpig 20 years, 6 months ago
Hey all, I''ve got a function which takes a variable number of arguments (the ''...'' expression as its final parameter). I loop through the va_list and add each item (they''re all meant to be pointers to strings) to a std::vector. How do I know when I''ve reached the end of the list? Is it even possible to find out, without the introduction of a dummy ''eof'' argument? Superpig - saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4 ry. .ibu cy. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebu

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Advertisement
You need to figure out the number of arguments through some means other than the va_list. Using a required argument (like *printf does) or terminating the list using a special value are possible ways.
Carp. OK, thanks.

I think I''ll prefix the ''...'' argument with a int telling how many there are in the variable argument list. I can give it a default value of 0, so if you''re not passing any strings you just leave it off.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4
ry. .ibu cy. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebu

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement