Re: comma operator (was: how the macro works) by George
George
Wed Dec 12 23:19:00 PST 2007
Thanks for your clarification, Tim!
My question is answered.
regards,
George
"Tim Roberts" wrote:
> George <George@discussions.microsoft.com> wrote:
> >
> >My question is,
> >
> >I think using
> >
> >#define GETFOO (Foo( &counter ), counter)
> >
> >is the same as
> >
> >#define GETFOO Foo( &counter )
> >
> >So, no benefits of using , operator, right?
>
> No, you clearly have not been reading Uli's very helpful posts.
>
> The comma operator evaluates the expression on both sides, and returns the
> value of the expression on the RIGHT.
>
> So, for example:
>
> int i, j, k, l, m;
> m = (i = 2, j = 3, k = 4, l = 5, 6);
>
> After that statement, i==2, j==3, k==4, l==5, and m==6. m==6 because the
> comma operator returns the result on the RIGHT.
>
> So, in this:
> #define GETFOO (Foo( &counter ), counter)
>
> The "return" GETFOO is counter, because that's the value on the RIGHT.
> --
> Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.
>