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


function parameters

Recommended Posts

Hello! To start with, Im playing with new things when it comes to functions (such as function pointers etc) and I would like to know how to get the parameters passed to a function when I do this: void Test(int x, ...) { } I call my test function with: Test(10, 20, 30, "hi"); But I only know that x is 10. How do I access the other variables? What is the name used for "..."? Sorry for posting this, I would have searched... but I dont know what to search for Thanks

Share this post

Link to post
Share on other sites
This is an example from an open source chess program that I have read in the past that uses it. Search for the va_ functions on the net, or look them up in a reference book. You need to include stdarg.h I believe. This function below basically is just a printf() wrapper. In the program, it needed fflush() to be called after each outputs, so the author chose to do it like this.

void VSendToWinboard(const char * szFmt, ...)
char aszBuf[1024];
va_list lpArgPtr;

va_start(lpArgPtr, szFmt);
vsprintf(aszBuf, szFmt, lpArgPtr);
printf("%s\n", aszBuf);

Share this post

Link to post
Share on other sites