• Welcome to Valhalla Legends Archive.
 

Creating functions.

Started by Final, October 12, 2006, 12:32 AM

Previous topic - Next topic

Final

I have always wonderd how do you make a function with an unset amount of arguements its just been bothering me for a while can someone explain or point me to the way.

Here what im wondering about.

Regular function set arguements.
void reg(int arg1,int arg2);

Unset
void uns(what goes in here);
Utilization
uns(25,26);

// A c++ function that uses unset arguement number I THINK.

sprintf ()
sprintf (buffer,"%s..ect",argument ,argument argument ,argument ...ect);

K

Here's how it works.


// declare the function:
void printf(const char* format, ...);


at the beginning of the function:


va_list pa;
va_start (pa, format); // start the var args pointer at the first argument.


when you need to read another argument:

// to read the next argument, call va_arg with the var args ptr and the type of the next argument.
uint32_t next_arg = va_arg(pa, uint32_t);


when you're done:
va_end(pa);


hope this helps.

Rule


Final

Awsome guys thanks again. Im going to play around with it see if i can make something usefull lol.