[MOAB-dev] [PATCH] scdtest.cpp: print what failed on error

Jason Kraftcheck kraftche at cae.wisc.edu
Mon Nov 30 11:26:29 CST 2009


Jed Brown wrote:
> On Mon, 30 Nov 2009 09:22:11 -0600, Jason Kraftcheck <kraftche at cae.wisc.edu> wrote:
>> Why do you want to change this from a function to a macro?
> 
> So that it can print where the error actually occurred instead of the
> completely useless line number in the body of the inline function.
> Also, don't use the first patch, the second was much better.
> 

But I would still do something like:

#define error(err) error_((err), __FILE__, __LINE__ )

void error(MBErrorCode err, const char* file, int line )
{
  if (MB_SUCCESS != err) {
    ...
  }
}

because functions:
  a) are typesafe, b) allow setting of break points easily, and
  c) avoid multiple executions of an expression if the macro
  argument is an expression.

As you began with changing the function to a macro, and then added the
location stuff with your second patch, it seemed that perhaps printing the
location was not your only motivation for changing the function to a macro.

- jason


More information about the moab-dev mailing list