Jump to content
  • Advertisement
Sign in to follow this  
41ph4_r4p70r

c++ funcs - undefined parameter number

This topic is 5398 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 guys, anyone could help me out, I need to create a function with an undefined number or params (like printf() for instance), I need to know how to define one and how to know inside the body, how many params where passed by the user. Any help appreciated

Share this post


Link to post
Share on other sites
Advertisement
Look into the va_list, va_start, va_arg, and va_end macros - reading the documentation on those should provide you with some examples on how to do it.

A nice link is here.

Magius

Share this post


Link to post
Share on other sites
If you're using C++ there is almost certainly a better way to do it which does not circumvent the type system. What is it that you are trying to do?

Enigma

Share this post


Link to post
Share on other sites
Basically, I need a function that draws a poly (obviously, I have no idea of how many sides does the poly has), then I need a func that get as its input an undetermined number of points, that then I ll use to draw the poly as I said before.

Btw, Im under a linux box

Share this post


Link to post
Share on other sites
You could pass a pointer to an array of points as one argument and the number of points as another.

Share this post


Link to post
Share on other sites
Certainly, passing a pointer would be a suitable choice, but while Im here, I wanna learn how to make it the way I explained ... :)

And BTW again, I need to pass an extra parameter, something like

void func((int)+,QColor) or void func(QColor,(int)+)

and I think va_* are macros defined only for Microsoft compiler, and again, Im under a Linux box

Share this post


Link to post
Share on other sites
The va_* macros are standard C (in stdarg.h). If you can get ahold of K&R's C book, they give a good explanation of how to use them.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!