Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

va_list problem

This topic is 3724 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

I want to keep things as simple as possible for the user so I have decided I want to go with using a va_list rather than forcing the user to fill an STL container with the perameters. The problem is for that reason I also don't want to force the user to have a NULL perameter at the end... So is there someway I can find the end of the list without a NULL value or knowing how many there are?

Share this post


Link to post
Share on other sites
Advertisement
Perhaps I'm misunderstanding your question, but I'm not sure what you're trying to do is possible. You really need to at least be able to infer the number of additional arguments through one of the defined arguments (like how printf uses the format to deduce the expected arguments and their types). I could be wrong though, and you might also have a look at this reference to see if anything clicks.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sync Views
I want to keep things as simple as possible for the user so I have decided I want to go with using a va_list rather than forcing the user to fill an STL container with the perameters.


The users of what? The parameters to what? What are you even trying to make? There are almost definitely more optimal solutions than vargs, but we need more information on what you actually want to accomplish.

Share this post


Link to post
Share on other sites
You could use some form of template function. I don't know how well it would work but hey.
#define T_NULL 0
#define T_INT 1
#define T_SCENEGRAPH 32
class Base { public: int type; Base(int t) { type = t; } };
class Null : public Base { public: Null() : Base(T_NULL) { } };

// this way you only have to give it one or two of your own objects if you want
template <class P1, class P2, class P3, class P4, class P5>
void foo (P1 p1 = Null(), P2 p2 = Null(), P3 p3 = Null(), P4 p4 = Null(), P5 p5 = Null())
{
if (p1.type != T_NULL) {
// do some crazy thing with parameter one, whatever it is
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!