>Martin Sebor wrote:
>
>Eric Lemings wrote:
>>
>> Is there an macro function (or similar macro function) that calls the
>> rw_assert() function automatically passing it the __FILE__
>> and __LINE__ arguments?
>
>Unfortunately, there isn't. No. rw_assert() is a variable
>argument function and since C99 varargs macros haven't been
>introduced into C++ yet not all compilers support them.
>
Unless I'm misunderstanding what we are talking about, it seems that we
can get around that pretty easily..
// in driver.h
struct rw_diag_obj
{
rw_diag_obj (diag_t diag, const char* file, int line)
: diag_(diag), file_(file), line_(line) { }
// implemented in driver.cpp
bool operator()(int success, const char* fmt, ...);
const diag_t diag_;
const char const* file_;
const int line_;
};
// someone will probably want to select better names
#define rw_fatal_x rw_diag_obj(diag_fatal , __FILE__, __LINE__)
#define rw_error_x rw_diag_obj(diag_error , __FILE__, __LINE__)
#define rw_assert_x rw_diag_obj(diag_assert, __FILE__, __LINE__)
#define rw_warn_x rw_diag_obj(diag_warn , __FILE__, __LINE__)
#define rw_note_x rw_diag_obj(diag_note , __FILE__, __LINE__)
// in driver.cpp
bool rw_diag_obj::operator()(int success, const char* fmt, ...)
{
va_list va;
va_start (va, fmt);
_rw_vdiag (diag_, 0 == success, file_, line_, fmt, va);
va_end (va);
return success;
}
There might be a small amount of overhead to do this, but it should be
optimized in most cases.
Travis
>Martin
>