Velocity Reviews > Can A Macro Do This?

# Can A Macro Do This?

gamename
Guest
Posts: n/a

 11-28-2007
Hi

Right now I do multiple asserts to verify multiple values:
assert(foo==X);
assert(foo==Y);
assert(foo==Z);

Is there any way to macro-ize this and do it in one call?
MYASRT(foo, (X||Y||Z));
... or maybe...
MYASRT(foo,OR,X,Y,Z));

TIA,
-T

santosh
Guest
Posts: n/a

 11-28-2007
gamename wrote:

> Hi
>
> Right now I do multiple asserts to verify multiple values:
> assert(foo==X);
> assert(foo==Y);
> assert(foo==Z);
>
> Is there any way to macro-ize this and do it in one call?
> MYASRT(foo, (X||Y||Z));
> ... or maybe...
> MYASRT(foo,OR,X,Y,Z));

What's wrong with:

assert(foo == X || foo == Y || foo == Z);

jacob navia
Guest
Posts: n/a

 11-28-2007
santosh wrote:
> gamename wrote:
>
>> Hi
>>
>> Right now I do multiple asserts to verify multiple values:
>> assert(foo==X);
>> assert(foo==Y);
>> assert(foo==Z);
>>
>> Is there any way to macro-ize this and do it in one call?
>> MYASRT(foo, (X||Y||Z));
>> ... or maybe...
>> MYASRT(foo,OR,X,Y,Z));

>
> What's wrong with:
>
> assert(foo == X || foo == Y || foo == Z);
>
>

That is wrong!
Should be:

assert(foo == X && foo == Y && foo == Z);

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

santosh
Guest
Posts: n/a

 11-28-2007
jacob navia wrote:

> santosh wrote:
>> gamename wrote:
>>
>>> Hi
>>>
>>> Right now I do multiple asserts to verify multiple values:
>>> assert(foo==X);
>>> assert(foo==Y);
>>> assert(foo==Z);
>>>
>>> Is there any way to macro-ize this and do it in one call?
>>> MYASRT(foo, (X||Y||Z));
>>> ... or maybe...
>>> MYASRT(foo,OR,X,Y,Z));

>>
>> What's wrong with:
>>
>> assert(foo == X || foo == Y || foo == Z);
>>
>>

>
> That is wrong!
> Should be:
>
>
> assert(foo == X && foo == Y && foo == Z);

Oops yes. You are right.

In my defence I got sidetracked by the "MYASRT" macro presented by the
OP, where he uses the OR operator, instead of the AND.

jacob navia
Guest
Posts: n/a

 11-28-2007
santosh wrote:
> jacob navia wrote:
>
>> santosh wrote:
>>> gamename wrote:
>>>
>>>> Hi
>>>>
>>>> Right now I do multiple asserts to verify multiple values:
>>>> assert(foo==X);
>>>> assert(foo==Y);
>>>> assert(foo==Z);
>>>>
>>>> Is there any way to macro-ize this and do it in one call?
>>>> MYASRT(foo, (X||Y||Z));
>>>> ... or maybe...
>>>> MYASRT(foo,OR,X,Y,Z));
>>> What's wrong with:
>>>
>>> assert(foo == X || foo == Y || foo == Z);
>>>
>>>

>> That is wrong!
>> Should be:
>>
>>
>> assert(foo == X && foo == Y && foo == Z);

>
> Oops yes. You are right.
>
> In my defence I got sidetracked by the "MYASRT" macro presented by the
> OP, where he uses the OR operator, instead of the AND.
>

Yes but now that I think about it...

How can foo be 3 different things at the same time as in the
original code???
>>>> assert(foo==X);
>>>> assert(foo==Y);
>>>> assert(foo==Z);

That can't be right!

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

santosh
Guest
Posts: n/a

 11-28-2007
jacob navia wrote:

> santosh wrote:
>> jacob navia wrote:
>>
>>> santosh wrote:
>>>> gamename wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> Right now I do multiple asserts to verify multiple values:
>>>>> assert(foo==X);
>>>>> assert(foo==Y);
>>>>> assert(foo==Z);
>>>>>
>>>>> Is there any way to macro-ize this and do it in one call?
>>>>> MYASRT(foo, (X||Y||Z));
>>>>> ... or maybe...
>>>>> MYASRT(foo,OR,X,Y,Z));
>>>> What's wrong with:
>>>>
>>>> assert(foo == X || foo == Y || foo == Z);
>>>>
>>>>
>>> That is wrong!
>>> Should be:
>>>
>>>
>>> assert(foo == X && foo == Y && foo == Z);

>>
>> Oops yes. You are right.
>>
>> In my defence I got sidetracked by the "MYASRT" macro presented by
>> the OP, where he uses the OR operator, instead of the AND.
>>

>
> Yes but now that I think about it...
>
> How can foo be 3 different things at the same time as in the
> original code???
> >>>> assert(foo==X);
> >>>> assert(foo==Y);
> >>>> assert(foo==Z);

>
> That can't be right!

Yes. The sequence of assert invocations as presented seem redundant. Of
course some code could occur between the calls or the OP might have
just presented this as an example to enquire about writing complex
expressions with assert.

gamename
Guest
Posts: n/a

 11-28-2007
> Yes. The sequence of assert invocations as presented seem redundant. Of
> course some code could occur between the calls or the OP might have
> just presented this as an example to enquire about writing complex
> expressions with assert.

Correct. The example is simplified for that purpose.

Björn Paetzel
Guest
Posts: n/a

 11-28-2007
santosh schrieb:

>> How can foo be 3 different things at the same time as in the
>> original code???
>> >>>> assert(foo==X);
>> >>>> assert(foo==Y);
>> >>>> assert(foo==Z);

>>
>> That can't be right!

>
> Yes. The sequence of assert invocations as presented seem redundant. Of
> course some code could occur between the calls or the OP might have
> just presented this as an example to enquire about writing complex
> expressions with assert.

Maybe he wanted to something like this:

assert(foo==X==Y==Z);

/* */

--
OMG,-10==10 in linux!

CBFalconer
Guest
Posts: n/a

 11-28-2007
jacob navia wrote:
> santosh wrote:
>> jacob navia wrote:
>>

.... snip ...
>>>
>>> assert(foo == X && foo == Y && foo == Z);

>>

.... snip ...
>
> Yes but now that I think about it...
>
> How can foo be 3 different things at the same time as in the
> original code???
>
>>>>> assert(foo==X);
>>>>> assert(foo==Y);
>>>>> assert(foo==Z);

>
> That can't be right!

#define foo n++
#enum {X, Y, Z);
int n = 0;

Now it passes the assert

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Guest
Posts: n/a

 11-28-2007
On Nov 28, 3:17 pm, jacob navia <(E-Mail Removed)> wrote:
> santosh wrote:
> > jacob navia wrote:

>
> >> santosh wrote:
> >>> gamename wrote:

>
> >>>> Hi

>
> >>>> Right now I do multiple asserts to verify multiple values:
> >>>> assert(foo==X);
> >>>> assert(foo==Y);
> >>>> assert(foo==Z);

>
> >>>> Is there any way to macro-ize this and do it in one call?
> >>>> MYASRT(foo, (X||Y||Z));
> >>>> ... or maybe...
> >>>> MYASRT(foo,OR,X,Y,Z));
> >>> What's wrong with:

>
> >>> assert(foo == X || foo == Y || foo == Z);

>
> >> That is wrong!
> >> Should be:

>
> >> assert(foo == X && foo == Y && foo == Z);

>
> > Oops yes. You are right.

>
> > In my defence I got sidetracked by the "MYASRT" macro presented by the
> > OP, where he uses the OR operator, instead of the AND.

>
> Yes but now that I think about it...
>
> How can foo be 3 different things at the same time as in the
> original code???
> >>>> assert(foo==X);
> >>>> assert(foo==Y);
> >>>> assert(foo==Z);

>
> That can't be right!

Perhaps foo is a macro with side-effects?

>
> --
> jacob navia
> jacob at jacob point remcomp point fr
> logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32