C Pocket Reference by Peter Prinz & Ulla Prinz

C Pocket Reference by Peter Prinz & Ulla Prinz

Author:Peter Prinz & Ulla Prinz
Language: eng
Format: epub
ISBN: 9780596103965
Publisher: O'Reilly Media, Inc.
Published: 2009-03-31T16:00:00+00:00


After reading out the argument list, the function should invoke the va_end macro before returning control to the caller. The only parameter of va_end is the arglist object.

Following is an example of a function, named max, that accepts a variable number of arguments:

// Determine the maximum of a number of positive integers. // Parameters: a variable number of positive values of // type unsigned int. The last argument must be 0. // Return value: the maximum of the arguments #include <stdarg.h> unsigned int max( unsigned int first, ... ) { unsigned int maxarg, arg; va_list arglist; // The optional-argument // list object va_start( arglist, first ); // Set arglist to deliver // the first optional // argument arg = maxarg = first; while ( arg != 0 ) { arg = va_arg( arglist, unsigned );// Get an argument if ( arg > maxarg ) maxarg = arg; } va_end( arglist ); // Finished reading the // optional arguments return maxarg; }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.