Bill Pursell wrote:
In libabc, I have a function which takes a NULL-terminated array
of character strings. A second, closely related function take
a NULL-terminated array of void *:
abc_foo( char ** );
abc_vfoo( void **);
I'd like to add 4 similar functions: a variadic version that
takes a char * as its first argument, a variadic version
that takes a void * as its first arg, and similar versions that
take a va_list:
abc_xxx( char *, ...);
abc_xxx( void *, ...);
abc_xxx( char *, va_list);
abc_xxx( void *, va_list);
I think I've already misnamed abc_vfoo(), since one
convention would imply that abc_vfoo() takes a va_list,
but I have no good ideas on the proper naming scheme
for the other 4 functions. I'm looking for ideas on how
to properly mangle these names. How would you
replace the 'xxx' above?
Generally functions should be named after what they do, not their
signatures. Here you seem to have a lot of functionally similar
functions. Such situations are indeed a nightmare when it comes to
sensible naming - just witness the amount of confusingly similar names
for functions in GNU GMP.
The C Standard itself prefixes a 'v' to functions taking a va_list.
You might follow that convention. You could also suffix a 'var' or
'_var' to the variadic ones.
But, IMHO, your best strategy might be to try to refactor your code so
that you minimise the number of functionally similar routines. This
might lead to a very slight loss of runtime efficiency but it might be
worth it in terms of code clarity. Try to have a single "interface"
function that accepts several types of arguments and, depending on the
type passed for each invocation, calls one of several "private"
functions to do the actual job. This does result in some compromise
with regard to type safety, but it might be worth it.