G
Guest
This question is borderline between language and programming, but I want to
focus more on the language standards issue, rather than the programming issue,
so I am posting here.
I have a number of functions which are front-ended by macros which make some
changes in the way the functions are called. There are various things being
done, but one simple example would be a function that takes a variable number
of (const char *) arguments and joins all the strings together into a single
string, where a NULL is the sentinel at the end of the arguments. The macro
front end adds that NULL so the calling program is less cluttered with detail.
What I have been doing with this is giving the macro the interface name and
naming the function slightly different. I have been putting a "_" in front
of the function name, which I want to get away from doing. So I have a macro
like:
#define strjoin(a...) (_strjoin(a,((const char*)(NULL))))
and a function definition like:
char *_strjoin(const char *s,...)
The alternative I'm looking at is to just use the same name for both macro
and function, like:
#define strjoin(a...) ((strjoin)(a,((const char*)(NULL))))
and:
char *(strjoin)(const char *s,...)
This approach works, but I'm worried about confusion it may cause. So what I
want to do here is see if there is a better alternative to using a different
function name than the one shown above. Would lots of "_" characters help
avoid conflicts? Like maybe:
#define strjoin(a...) (__strjoin__(a,((const char*)(NULL))))
and:
char *__strjoin__(const char *s,...)
focus more on the language standards issue, rather than the programming issue,
so I am posting here.
I have a number of functions which are front-ended by macros which make some
changes in the way the functions are called. There are various things being
done, but one simple example would be a function that takes a variable number
of (const char *) arguments and joins all the strings together into a single
string, where a NULL is the sentinel at the end of the arguments. The macro
front end adds that NULL so the calling program is less cluttered with detail.
What I have been doing with this is giving the macro the interface name and
naming the function slightly different. I have been putting a "_" in front
of the function name, which I want to get away from doing. So I have a macro
like:
#define strjoin(a...) (_strjoin(a,((const char*)(NULL))))
and a function definition like:
char *_strjoin(const char *s,...)
The alternative I'm looking at is to just use the same name for both macro
and function, like:
#define strjoin(a...) ((strjoin)(a,((const char*)(NULL))))
and:
char *(strjoin)(const char *s,...)
This approach works, but I'm worried about confusion it may cause. So what I
want to do here is see if there is a better alternative to using a different
function name than the one shown above. Would lots of "_" characters help
avoid conflicts? Like maybe:
#define strjoin(a...) (__strjoin__(a,((const char*)(NULL))))
and:
char *__strjoin__(const char *s,...)