Say you're designing a C API, and one of your big concerns is ABI stability (it's going to be deployed as a shared library, or whatever).
You have a function exported
int foo_bar(int a, int b, int* c);
And you feel that someday, you may need to add one or more parameters to this function, but you don't know which ones yet.
You come up with the following solution
int foo_bar(int a, int b, int* c, int ver,...) ;
#define FOO_BAR_V1 0xA9520F00
And document that ver
is reserved, and must always be set to FOO_BAR_V1
, and additional parameters were ignored.
You then plan that, when you nail down the additional parameter needed, say, an output buffer, you'll do the following
int foo_bar(int a, int b, int* c, int ver,/* char* buff, int buffSize, int* outSize*/...) ;
#define FOO_BAR_V2 (FOO_BAR_V1 + 1)
After typing this all out, it seems like there's not much point to this over just having two exported functions (is there? Other than not having to come up with a new name), so I guess I'll also ask if anyone knows of any libraries that do this, or something similar?
stdio.h
functions along with a number of theunistd.h
functions make use of variadic input. (printf
,fprintf
,sscanf
, etc.. andexecl
, et.al., theulimit
function`...) There is nothing wrong, or uncommon about it, as long as you have some yet to be determined number of parameters of the same type. There is a standard for handling variadic input and it isn't much to become familiar with.