473,931 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can A Macro Do This?

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
On Mon, 03 Dec 2007 08:58:28 +0000, Philip Potter <pg*@doc.ic.ac. uk>
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.
Well, if that were true this would produce three statements of
equality. It's a shame it won't compile. But, if you are not allowed
to compare them, how can you say they are equal?

#include <stdio.h>
int main(void){
int x[2];
int *a;
void *b;
int (*c)[2];
a = x;
b = x;
c = &x;
if (a == b) puts("a == b");
if (b == c) puts("b == c");
if (a == c)
puts("a == c");
else
puts("a != c");
getchar();
return 0;}
Remove del for email
Dec 6 '07 #21
Barry Schwarz wrote:
On Mon, 03 Dec 2007 08:58:28 +0000, Philip Potter <pg*@doc.ic.ac. uk>
wrote:
>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.

Well, if that were true this would produce three statements of
equality. It's a shame it won't compile. But, if you are not allowed
to compare them, how can you say they are equal?

#include <stdio.h>
int main(void){
int x[2];
int *a;
void *b;
int (*c)[2];
a = x;
b = x;
c = &x;
if (a == b) puts("a == b");
if (b == c) puts("b == c");
if (a == c)
puts("a == c");
else
puts("a != c");
getchar();
return 0;}
It compiles on mine:

pgp@medusa-s2:~/tmp$ gcc -ansi -pedantic bs.c -obs
bs.c: In function `main':
bs.c:12: warning: comparison of distinct pointer types lacks a cast
pgp@medusa-s2:~/tmp$ ./bs
a == b
b == c
a == c
pgp@medusa-s2:~/tmp$

....although I accept that it's not guaranteed to compile everywhere.

I came up with a very similar example in <fj**********@a ioe.org>, which
I posted three days ago:
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.

If we change the problem and limit ourselves to strictly-conforming
programs, is it possible to come up with expressions a, b, and c for
which a == b and b == c but a != c?
Dec 6 '07 #22
ja*********@ver izon.net wrote:
Philip Potter wrote:
[snip]
#include <stdio.h>
#include <limits.h>
int main(void)
{
int a = -1;
unsigned b = UINT_MAX;
double c = b;

printf("a%c=b\n ", a==b ? '=' : '!');
printf("b%c=c\n ", b==c ? '=' : '!');
printf("a%c=c\n ", a==c ? '=' : '!');
return 0;
}

Output:
a==b
b==c
a!=c
Nice. Thanks a lot.
Dec 6 '07 #23
On Thu, 06 Dec 2007 13:14:19 +0000, Philip Potter <pg*@doc.ic.ac. uk>
wrote:
>I came up with a very similar example in <fj**********@a ioe.org>, which
I posted three days ago:
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.
This is the only point I was trying to make.
>

If we change the problem and limit ourselves to strictly-conforming
programs, is it possible to come up with expressions a, b, and c for
which a == b and b == c but a != c?
I expect there are floating point values, let's call one such value X,
for which
float a = X;
double b = X;
long double = X;
produces the situation in question due to the manner in which floating
point values are approximated. Unfortunately, I can't test it on my
system since long double and double have the same representation.
Remove del for email
Dec 9 '07 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1531
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...
699
34890
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...
3
2639
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?
2
3507
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...
4
6297
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...
3
8495
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();")
8
10872
by: lasek | last post by:
Hi...in some posts i've read...something about using macro rather then function...but difference ??. Best regards....
6
6446
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
5
3501
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...
5
10615
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
0
10121
marktang
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...
0
9952
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11495
Oralloy
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...
0
11071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8195
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7359
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();...
0
6263
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4887
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
2
4431
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.