Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

warning: extra tokens at end of #undef directive

198 views
Skip to first unread message

johnnyzhou

unread,
Dec 21, 2009, 12:35:57 AM12/21/09
to
Hi, folks :

How can I avoid this warning , thanks ~~~

B,R
Johnny

Ian Collins

unread,
Dec 21, 2009, 1:47:39 AM12/21/09
to
johnnyzhou wrote:
> Hi, folks :
>
> How can I avoid this warning , thanks ~~~
>
By not adding any extra tokens at end of an #undef directive?

Show an example.

--
Ian Collins

red floyd

unread,
Dec 21, 2009, 12:18:07 PM12/21/09
to

Doctor, it hurts when I do "this".

I am guessing that the OP is doing something like this:

#undef A B

trying to undef both and b, but that's just a guess.

johnnyzhou

unread,
Dec 21, 2009, 8:49:50 PM12/21/09
to
red floyd 写道:

Sorry , this is my example , please help check :

void textDef(MyStruct *a, MyStruct *b, MyStruct *c )
{
int result;
CompVar lsVar = a->var();
CompVar midVar = c->var();
CompVar lgVar = b->var();

#define MyCheckVar(A,B,r); \
if( A==B ) r=-1; \
else if( A==lsVar && B==midVar ) r=1; \
else r=0;

.....

MyCheckVar( pa->var(), pb->var(), result );

.....

#undef MyCheckVar(A,B,r);

.....

}

B,R
Johnny

Jonathan Lee

unread,
Dec 21, 2009, 9:24:59 PM12/21/09
to
On Dec 21, 8:49 pm, johnnyzhou <0121...@163.com> wrote:
> Sorry , this is my example , please help check :
> #define  MyCheckVar(A,B,r); \
>    if( A==B  ) r=-1; \
>    else if( A==lsVar && B==midVar ) r=1; \
>    else r=0;
>    .....
> #undef MyCheckVar(A,B,r);

Just "#undef MyCheckVar"

Also, it's not advisable to use a macro for something
like this. See, for example, here:

http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.4

and

http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.5

Why not something like

inlin int check_var(CompVar A, CompVar B) {
return (A == B ? -1 : (A == lsVar && B == midVar ? 1 : 0))
}

?
--Jonathan

johnnyzhou

unread,
Dec 21, 2009, 10:32:34 PM12/21/09
to
Jonathan Lee 写道:

Dear Jonathan:
Thanks for your help ~~~ ^__^

0 new messages