473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

need help on a syntax in conditional operator

Hello there,

I need help on understanding part of the macro below:

#define MY_MACRO( OP, RESULT ) \
( (RESULT = (OP)) != 0 ? (errno = RESULT, -1) : 0 )

What I do not understand is how is the part (errno = RESULT, -1)
get evaluated.

Bill
Jul 22 '05 #1
2 1034
Bill Davidson wrote in
news:c1**************************@posting.google.c om in comp.lang.c++:
Hello there,

I need help on understanding part of the macro below:

#define MY_MACRO( OP, RESULT ) \
( (RESULT = (OP)) != 0 ? (errno = RESULT, -1) : 0 )

What I do not understand is how is the part (errno = RESULT, -1)
get evaluated.


The default behaviour of the , (comma) operator is to evaluate
the left expression and dicard the result and then to evaluate
the right expression:

value = ( evalute_and_dicard, result );

value = ( evalute_and_dicard, evalute_and_dicard_2, result );

Both of the above would assign result to value.

Assuming OP and RESULT in your example above are int's we could
rewrite it as:

inline int my_function( int op, int &result )
{
int return_value;

result = op;
if ( result != 0 )
{
errno = result;
return_value = -1;
}
else
{
return_value = 0;
}

return return_value;
}

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
On Wed, 21 Apr 2004, Bill Davidson wrote:
#define MY_MACRO( OP, RESULT ) \
( (RESULT = (OP)) != 0 ? (errno = RESULT, -1) : 0 )

What I do not understand is how is the part (errno = RESULT, -1)
get evaluated.


The comma in between the assignment and -1 is the sequencing operator.
The expressions are evaluated from left to right: RESULT is assigned to
errno, and the overall value will be -1.

BTW you are more likely to find this sort of code in C than in C++.

--
Claudio Jolowicz
http://www.doc.ic.ac.uk/~cj603

Jul 22 '05 #3

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

Similar topics

177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
4
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
6
by: Chris Dunaway | last post by:
Consider this code (.Net 2.0) which uses a nullable type: private void button1_Click(object sender, System.EventArgs e) { DateTime? nullableDate; nullableDate = (condition) ? null :...
9
by: Marty | last post by:
Hi, Does using the the conditional operator (?:) instead of the common "if" statement will give a performance gain in a C# .NET 2003 application (even in C# .NET 2005?). What is the advantage...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
6
by: rshepard | last post by:
All my python books and references I find on the web have simplistic examples of the IF conditional. A few also provide examples of multiple conditions that are ANDed; e.g., if cond1: if cond2:...
15
by: Nicholas M. Makin | last post by:
I was just thinking that I understood the conditional operator when I coded the following expecting it to fail: int a= 10, b= 20, c= 0; ((a < b) ? a : b) = c; // a=0 a=20; b= 10; ((a < b) ? a...
13
by: Neal Becker | last post by:
In hindsight, I am disappointed with the choice of conditional syntax. I know it's too late to change. The problem is y = some thing or other if x else something_else When scanning this my...
1
by: Cameron Simpson | last post by:
On 23Sep2008 19:52, Neal Becker <ndbecker2@gmail.comwrote: | In hindsight, I am disappointed with the choice of conditional syntax. | I know it's too late to change. The problem is | | y = some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.