Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: Stupid Macr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 1034 of 1126
Post > Topic >>

Re: Stupid Macro Tricks Query

by Minimiscience <minimiscience+usenet@[EMAIL PROTECTED] > Jan 14, 2008 at 12:50 PM

gamename <namesagame-usenet@[EMAIL PROTECTED]
> writes:

> I use CUnit for testing which uses a variation of "assert()" for
>error detection.
>
>Right now I do multiple asserts to verify multiple values.
>Ex.
>     CU_ASSERT(foo==X); CU_ASSERT(foo==Y); CU_ASSERT(foo==Z);

Unless X, Y, and Z are the same, at least two of those are going to fail. 
Are
you sure that's what you want to do?

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

Making a macro of this would only be possible if you called the macro with
the
exact same number of arguments each time, as variable-argument macros are
not
possible in standard C.  Assuming that you want a macro that tests foo
against
three values each time, you can do:

#define MYASRT(foo, a, b, c)  CU_ASSERT((foo)==(a));
CU_ASSERT((foo)==(b)); \
 CU_ASSERT((foo)==(c))
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 4 Posts in Topic:
Stupid Macro Tricks Query
gamename <namesagame-u  2008-01-12 19:02:05 
Re: Stupid Macro Tricks Query
Keith Thompson <kst-u@  2008-01-14 12:49:14 
Re: Stupid Macro Tricks Query
Minimiscience <minimis  2008-01-14 12:50:25 
Re: Stupid Macro Tricks Query
Keith Thompson <kst-u@  2008-02-17 12:03:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 0:11:07 CDT 2008.