c va_list example
snippet in c

c va_list example

user7238

void example_func(int var, ...)
{
	//the variable
	va_list va;
  	//initalizing the arguments list with the first parametter
  	va_start(va, var);
  
  	//read a parametter (list, type)
  	//each call of va_arg will give next argument, but type must be
	//correctly specified otherwise the behaviour is unpredictable
  	// Don't forget type promotion!!! (e.g.: char -> int)
  	va_arg(va, int);
  	//You can also send the list once initialized to another function:
  	exemple_func2(&va);
  	//destroying the list
  	va_end(va);
}

void example(va_list *va)
{
  //No need to initialize / destroy the list, just get the args with
  va_list(*va, int);
}