Public Group

va_list problem

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

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 on other sites
What are you trying to do?

What kind of values are you passing?

Share on other sites
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 on other sites
Quote:
 Original post by Sync ViewsI 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 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 32class 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 wanttemplate <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    }}

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 27
• 16
• 10
• 10
• 11
• Forum Statistics

• Total Topics
634099
• Total Posts
3015526
×