question about directives

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rcoutts@comcast.net

    #1

    question about directives

    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=enumFooCl ass;}
    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==enumFooC lass) ? (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==enumFooC lass).....

    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

  • tigervamp

    #2
    Re: question about directives


    rcoutts@comcast .net wrote:[color=blue]
    > I just wrote a simple directive to test if the casting of a class[/color]

    C does not have classes, ask in comp.lang.c++

    Rob Gamble

    Comment

    • Martin Ambuhl

      #3
      Re: question about directives

      rcoutts@comcast .net wrote:[color=blue]
      > I just wrote a simple directive to test if the casting of a class
      > pointer has the proper member variable setting.[/color]

      You need to take your C++ questions to <news:comp.lang .c++>. C++ and C
      are different languages.

      Comment

      Working...