macro help



 DEVELOP > c-Plus-Plus > macro help

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 21 Oct 2006 08:45:13 PM
Object: macro help
guys,
I have to do some testing, and usally code flows like this. If
something is wrong, flag error. And if it is correct, see if something
else is wrong, flag error! And recursive like that.
if (a != b) {
flag_error();
}
else {
if ( c != d) {
flag_error();
}
else {
if ( e != f) {
flag_error();
}
} //end of else c != d
} //end of else a !=b
it is really annoying to read code later for debugging. Using a !=b ?
flag_error() : c != d ? ...doesn't seem that practical either.
how can I convert this into macro so that I can use it more readable
something like this!
VERIFY a == b OTHERWISE flag_error();
GO_NEXT;
VERIFY c == d OTHERWISE flag_error();
GO_NEXT;
VERIFY e == f OTHERWISE flag_error();
is this recursive macro possible.
Sorry, for asking dumb quesitons. Trying to make life easy, if possible.
.

User: "Clark S. Cox III"

Title: Re: macro help 21 Oct 2006 08:52:51 PM
wrote:

guys,
I have to do some testing, and usally code flows like this. If
something is wrong, flag error. And if it is correct, see if something
else is wrong, flag error! And recursive like that.

if (a != b) {
flag_error();
}
else {
if ( c != d) {
flag_error();
}
else {
if ( e != f) {
flag_error();
}
} //end of else c != d
} //end of else a !=b

What's wrong with (it seems at least as readable as your proposed solution):
if (a != b) {
flag_error();
}
else if ( c != d) {
flag_error();
}
else if ( e != f) {
flag_error();
}
else
{
//If we get here, nothing is wrong
}
Or, using exceptions:
if (a != b) {
throw some_error;
}
if ( c != d) {
throw some_error;
}
if ( e != f) {
throw some_error;
}
//If we get here, nothing is wrong
--
Clark S. Cox III
clarkcox3@gmail.com
.

User: "David Harmon"

Title: Re: macro help 21 Oct 2006 09:04:09 PM
On 21 Oct 2006 18:45:13 -0700 in comp.lang.c++,

wrote,

I have to do some testing, and usally code flows like this. If
something is wrong, flag error. And if it is correct, see if something
else is wrong, flag error! And recursive like that.

It's actually not recursive; rather, it's alternative.
My version:
if ((a != b)
|| (c != d)
|| (e != f)) flag_error();
.
User: "Fox"

Title: Re: macro help 22 Oct 2006 05:51:11 AM

if ((a != b)
|| (c != d)
|| (e != f)) flag_error();

That's good if there is one error to all cases.
.
User: "David Harmon"

Title: Re: macro help 22 Oct 2006 10:27:30 AM
On Sun, 22 Oct 2006 12:51:11 +0200 in comp.lang.c++, "Fox"
<roxyfox@o2.pl> wrote,


if ((a != b)
|| (c != d)
|| (e != f)) flag_error();


That's good if there is one error to all cases.

That seemed to be the example given.
If not, then my next suggestion is:
if (a != b) return flag_error();
if (c != d) return flag_error();
if (e != f) return flag_error();
.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER