Archived

This topic is now archived and is closed to further replies.

Variable argument lists

This topic is 5173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites