c va list example

Solutions on MaxInterview for c va list example by the best coders in the world

showing results for - "c va list example"
Victor
22 Jun 2016
1void example_func(int var, ...)
2{
3	//the variable
4	va_list va;
5  	//initalizing the arguments list with the first parametter
6  	va_start(va, var);
7  
8  	//read a parametter (list, type)
9  	//each call of va_arg will give next argument, but type must be
10	//correctly specified otherwise the behaviour is unpredictable
11  	// Don't forget type promotion!!! (e.g.: char -> int)
12  	va_arg(va, int);
13  	//You can also send the list once initialized to another function:
14  	exemple_func2(&va);
15  	//destroying the list
16  	va_end(va);
17}
18
19void example(va_list *va)
20{
21  //No need to initialize / destroy the list, just get the args with
22  va_list(*va, int);
23}