question about directives

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
 
M

Martin Ambuhl

I just wrote a simple directive to test if the casting of a class
pointer has the proper member variable setting.

You need to take your C++ questions to < C++ and C
are different languages.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top