Skip to main content
gamedev.net
🔒 Locked

function parameters

Started by Redoc Apr 28, 2003 at 10:11 PM 2 replies 300+ views
Original Post
Redoc
Redoc
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
Russell
Russell
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);
fflush(stdout);
}
[/quote]
Jan Wassenberg
Jan Wassenberg
Did the author not know about setvbuf(stdout, NULL, _IONBF, 0), or does that not work for some reason? (I haven''t tried it)
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Kuladus
Kuladus
yep use the std variable arguments library function

#include <stdarg.h>

+ + +

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.