I have re-written assert to serve my own purpose. I want to hide debug implementation details from the "callers" using functions. Basically, a string parameter in my functions will be hidden from them and that string will contain debug information. I want my assert's to do the following:
1)failed statement, line, file, function
2)line, file, function (where call originated from)
This is because my code i need to test is seperate from my "main" application.
example:
Code:
main.c //origin of call
int main()
{
dosomething();
}
Code:
dosomething.c //where code being tested is
int dosomething()
{
myassert( statement ); //tell me statement, function, line, file (and origin line, file, function)
}
Here is what i've come up with, but the __FUNCTION__ or __func__ doesn't expand, it just prints as __FUNCTION__ or __func__.... The following is an example, in the same file but it is only an example!
Code:
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define LOCATION __FILE__ ":" TOSTRING(__LINE__) //<---I want the __func__ here...
#ifdef NDEBUG
#define CHECK(ignore)((void) 0)
#else
#define CHECK(x) \
{ \
if( !(x) ) \
{ \
fprintf(stderr, "%s %s %s", TOSTRING(x), LOCATION, origin ); \
exit(1); \
} \
}
#endif
//when caller uses this function, they don't know about the "char *origin" parameter
void myfunction( char *origin, int index, int value )
{
CHECK( index == 2 );
}
#define myfunction(...) myfunction(LOCATION,__VA_ARGS__) //hide implementation details
int main ()
{
myfunction(1,2); //use the same way whether debugging is on or off
return( 0 );
}
Thanks in advance..Oh, and the macros __FUNCTION__ etc.. do work on their own if I were to use printf("%s", __FUNCTION__); but that's not what i'm looking for. I would like to append it to my define, thanks.