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
Nov 28 '07
23 1484
CBFalconer wrote:
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 :-)
A macro with side effects within an
assert() expression.
That is *really* a bad programming style. Yes
everything is possible but *that* would be an abomination,
and a useless one, since the assert macro would NOT
increment the "counter" if NDEBUG was defined!
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32
gamename <namesagame-use...@yahoo.co mwrote:
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));
assert(foo == X || foo == Y || foo == Z);
--
Peter
Someone wrote:
assert(foo==X);
assert(foo==Y);
assert(foo==Z);
CBFalconer <cb********@yah oo.comwrites:
#define foo n++
#enum {X, Y, Z);
int n = 0;
Now it passes the assert :-)
Is assert guaranteed to evaluate its argument only once (without
NDEBUG)?
(Also, enum is not a preprocessor directive, and its list of
enumeration values ends in }).
--
char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x11f6} ,*p
=b,i=24;for(;p+ =!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}
On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e>
wrote:
>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);
/* ;) */
Since == is not transitive in the same sense = is, it seems unlikely.
Remove del for email
Barry Schwarz wrote:
On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e>
wrote:
>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);
/* ;) */
Since == is not transitive in the same sense = is, it seems unlikely.
A relation R is transitive if a R b && b R c implies a R c for all
a,b,c. I believe this applies to == and it's even appropriate for =
because it isn't a relation.
Philip Potter wrote:
>
Barry Schwarz wrote:
On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e>
wrote:
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);
/* ;) */
Since == is not transitive in the same sense = is, it seems unlikely.
A relation R is transitive if a R b && b R c implies a R c for all
a,b,c. I believe this applies to == and it's even appropriate for =
because it isn't a relation.
(NULL == 0) /* defined */
( 0.0 == 0) /* defined */
(NULL == 0.0) /* undefined */
--
pete
On Fri, 30 Nov 2007 12:54:04 +0000, Philip Potter <pg*@doc.ic.ac. uk>
wrote:
>Barry Schwarz wrote:
>On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e> wrote:
>>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 expression s with assert. Maybe he wanted to something like this:
assert(foo==X ==Y==Z);
/* ;) */
Since == is not transitive in the same sense = is, it seems unlikely.
A relation R is transitive if a R b && b R c implies a R c for all a,b,c. I believe this applies to == and it's even appropriate for = because it isn't a relation.
Equality is transitive. The == operator is not.
Due to left to right associativity, the expression foo == X == Y == Z
is parsed as (((foo == X) == Y) == Z). The innermost expression must
evaluate to 0 or 1. If all four variables have the value 5, the
intuitive meaning of the expression should be TRUE but foo == X
evaluates to 1, 1 == Y evaluates to 0, and 0 == Z evaluates to 0 and
the expression is FALSE. Even if associativity were reversed, the
expression would still evaluate to FALSE.
Remove del for email
Barry Schwarz wrote:
On Fri, 30 Nov 2007 12:54:04 +0000, Philip Potter <pg*@doc.ic.ac. uk>
wrote:
>Barry Schwarz wrote:
>>On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e> wrote:
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 expressio ns with assert. Maybe he wanted to something like this:
assert(foo== X==Y==Z);
/* ;) */ Since == is not transitive in the same sense = is, it seems unlikely.
A relation R is transitive if a R b && b R c implies a R c for all a,b,c. I believe this applies to == and it's even appropriate for = because it isn't a relation.
Equality is transitive. The == operator is not.
Due to left to right associativity, the expression foo == X == Y == Z
is parsed as (((foo == X) == Y) == Z). The innermost expression must
evaluate to 0 or 1. If all four variables have the value 5, the
intuitive meaning of the expression should be TRUE but foo == X
evaluates to 1, 1 == Y evaluates to 0, and 0 == Z evaluates to 0 and
the expression is FALSE. Even if associativity were reversed, the
expression would still evaluate to FALSE.
You appear to have ignored my definition of transitivity.
If knowing that a == b && b == c means that you know for sure that a ==
c, then == is transitive. It has nothing to do with being able to use
the a == b == c syntax. As I said, I believe that == is transitive, but
I don't know the standard well enough to confirm this.
Philip Potter wrote:
Barry Schwarz wrote:
>On Fri, 30 Nov 2007 12:54:04 +0000, Philip Potter <pg*@doc.ic.ac. uk> wrote:
>>Barry Schwarz wrote: On Wed, 28 Nov 2007 16:45:40 +0100, Björn Paetzel <ne**@kolrabi.d e> wrote:
santosh schrieb: > >>How can foo be 3 different things at the same time as in the >>origina l 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 >expression s with assert. Maybe he wanted to something like this: > assert(foo= =X==Y==Z); > /* ;) */ Since == is not transitive in the same sense = is, it seems unlikely. A relation R is transitive if a R b && b R c implies a R c for all a,b,c. I believe this applies to == and it's even appropriate for = because it isn't a relation.
Equality is transitive. The == operator is not.
Due to left to right associativity, the expression foo == X == Y == Z is parsed as (((foo == X) == Y) == Z). The innermost expression must evaluate to 0 or 1. If all four variables have the value 5, the intuitive meaning of the expression should be TRUE but foo == X evaluates to 1, 1 == Y evaluates to 0, and 0 == Z evaluates to 0 and the expression is FALSE. Even if associativity were reversed, the expression would still evaluate to FALSE.
You appear to have ignored my definition of transitivity.
If knowing that a == b && b == c means that you know for sure that a ==
c, then == is transitive. It has nothing to do with being able to use
the a == b == c syntax. As I said, I believe that == is transitive, but
I don't know the standard well enough to confirm this.
Hmm, for a = (int *) 0, b = 0, c = (float *) 0:
a == b && b == c, but a == c is a constraint violation. I think. So ==
is not transitive in the mathematical sense.
jacob navia wrote:
>Now it passes the assert :-)
A macro with side effects within an
assert() expression.
That is *really* a bad programming style. Yes
everything is possible but *that* would be an abomination,
and a useless one, since the assert macro would NOT
increment the "counter" if NDEBUG was defined!
I believe you missed the smiley. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Donald 'Paddy' McCarthy |
last post by:
So, for those that don't actively not-want a Python macro facility.
If we are to have it what should it do?
1) Macro definitions should allow Doc strings.
2) There should be a separate statement to import Macro definitions
from another file.
3) Existing import of a module file containing module definitions
should NOT cause the module files macros to be 'active' in the file
that is importing.
A new macro import command would be needed...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
by: John |
last post by:
Please, consider this macro:
#define mymacro(arg1, arg2) arg1 and arg2
Then it is used:
mymacro(boys, girls)
How is its expansion?
|
by: Pete |
last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit
...) from a macro. It seems there used to be some wizard for that.
However in Access 2000 it seems you have to build your menus by
customizing a toolbar. With this method you have to create a separate
macro for every single menu and sub menu. The old method would allow
me to include several menus (File/ print/ page setup ...) all within
one macro. Now it seems I...
|
by: tmountjr |
last post by:
I've got a user who's trying to export a text file with unicode
formatting. When he exports it as straight ascii, some of the foreign
characters (mostly just accent marks and the like - no non-roman
characters that I can see) don't come through right. So he needs it in
Unicode formatting. He's using code for the DoCmd.OutputTo command.
There's a very undocumented Encoding option for that command, but no
options are specified and there's...
| |
by: Alexander Ulyanov |
last post by:
Hi all.
Is it possible to pass the whole blocks of code (possibly including
" and ,) as macro parameters?
I want to do something like:
MACRO(FOO, "Foo",
"return "Foobar";",
"foo(); bar();")
|
by: lasek |
last post by:
Hi...in some posts i've read...something about using macro rather then
function...but difference ??.
Best regards....
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the Autoexec Macro looks like
the way to go. Could someone please assist?
Thank you very much!
Mike
|
by: Bill |
last post by:
This database has no forms. I am viewing an Access table in datasheet
view. I'd like to execute a macro to execute a function (using
"runcode"). In the function, I'll reading data from the record the
cursor was on in the datasheet at the time I executed the macro.
So, the questions are: 1) In the macro, how to I get my hands on the
record key or record data of the record the cursor was on in the
datasheet at the time I executed the...
|
by: Peng Yu |
last post by:
Hi,
It is benifitical to use macro in certain cases.
http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html
However, I found that it is not easy to debug a macro. For example,
for the following program, I can not trace into the last macro in gdb.
In this sense, if I want to debug the code easily, should I avoid
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |