R
rcoutts
I just wrote a simple directive to test if the casting of a class
pointer has the proper member variable setting. So, for the class
(this is pseudo code)
class foo {
public:
foo() {type=enumFooClass;}
int type;
};
instead of saying
a = (foo*)val;
my directive would be used like
a = fooPtr(val);
and look like this:
#define fooPtr(f) (f!=NULL && (f)->type==enumFooClass) ? (foo*)f :
NULL)
So, if the type var checks out, things get cast as expected. If the
type var has the wrong setting, the directive returns NULL and a low
memory address condition exists (this is much more easily detected by
the debugger I'm using than an invalid cast).
I implemented this and it works great, but what I didn't see coming is
when I use a function call as the directive variable, it gets called
everytime "f" is referenced. E.g.,
fooPtr(bar(a)) gets implemented as (bar(a)!=NULL &&
bar(a)->type==enumFooClass).....
this can be a real problem if repeated calls to "bar(a)" perform an
operation, such as popping the variable off a stack, which is the
problem I'm having.
How do you write a directive such as this that will accomodate a
function call in the parens? I could just use an inline function, but
I'd rather not if I can do this with directives.
Thanks,
Rich
pointer has the proper member variable setting. So, for the class
(this is pseudo code)
class foo {
public:
foo() {type=enumFooClass;}
int type;
};
instead of saying
a = (foo*)val;
my directive would be used like
a = fooPtr(val);
and look like this:
#define fooPtr(f) (f!=NULL && (f)->type==enumFooClass) ? (foo*)f :
NULL)
So, if the type var checks out, things get cast as expected. If the
type var has the wrong setting, the directive returns NULL and a low
memory address condition exists (this is much more easily detected by
the debugger I'm using than an invalid cast).
I implemented this and it works great, but what I didn't see coming is
when I use a function call as the directive variable, it gets called
everytime "f" is referenced. E.g.,
fooPtr(bar(a)) gets implemented as (bar(a)!=NULL &&
bar(a)->type==enumFooClass).....
this can be a real problem if repeated calls to "bar(a)" perform an
operation, such as popping the variable off a stack, which is the
problem I'm having.
How do you write a directive such as this that will accomodate a
function call in the parens? I could just use an inline function, but
I'd rather not if I can do this with directives.
Thanks,
Rich