473,780 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comma operator

Hi,
I need some clarifications on how the comma operator is used to return
values from function like macros.I saw a typical implementation as :

#define sigfillset(ptr) ( *(ptr) &= ~(sigset_t)0 , 0 )

How is the 0 after the comma operator used to return 0 on success of the
macro function ?

TIA
Nov 14 '05 #1
2 1777
grid <pr******@gmail .com> wrote:
I need some clarifications on how the comma operator is used to return
values from function like macros.I saw a typical implementation as : #define sigfillset(ptr) ( *(ptr) &= ~(sigset_t)0 , 0 ) How is the 0 after the comma operator used to return 0 on success of the
macro function ?


`sigfillset' is not a function, it's a "function-like macro", but this
detail is not very important here. A macro does not return anything,
it gets expanded. In the above case, it gets expanded into a comma
expression, whose value is _always_ 0, regardless whether the first
operand expression succeeded or not.

The above code may be some sort of optimization (macro expansion
in place of function call). `sigfillset' is probably one of many
"functions" , which return 0 on success. Since setting a bit
pattern cannot ever fail, we can always "return" 0.

Example:
int error;
error = sigfillset(/*...*/);
if (error) abort();
error = sigfooset(/*...*/);
if (error) abort();
error = sigbarset(/*...*/);
if (error) abort();
/* etc... */

--
Stan Tobias
mailx `echo si***@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2
grid <pr******@gmail .com> wrote:
Hi,
I need some clarifications on how the comma operator is used to return
values from function like macros.I saw a typical implementation as :

#define sigfillset(ptr) ( *(ptr) &= ~(sigset_t)0 , 0 )

How is the 0 after the comma operator used to return 0 on success of the
macro function ?


Actually it allways returns 0. The point is that the comma-operator is
of such low precedence that the left operand of it is evaluated first,
so in the above case the assignement to *ptr is done and thereafter the
evaluation of the right hand operator of the ',' is done and becomes the
recult of the expression. So if it is meant to return 0 on success one
could rely on sigfillset to never fail.

OTOH, if ptr is not a valid pointer anything might happen.

--
Z (zo**********@w eb.de)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Nov 14 '05 #3

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

Similar topics

7
8034
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so something like this: 1) e = (a, b, c, d); // concatenate a,b,c,d into e 2) (a, b, c, d) = e; // get the bits of e into a,b,c, and d For example, in the second case, assume that a,b,c,d represent 2-bit integers, and e represents an 8-bit...
5
2574
by: Derek | last post by:
I came upon the idea of writting a logging class that uses a Python-ish syntax that's easy on the eyes (IMO): int x = 1; double y = 2.5; std::string z = "result"; debug = "Results:", x, y, z; The above example outputs:
2
2297
by: benben | last post by:
I am looking for a good example of overloading operator , (operator comma) Any suggestions? Ben
7
2966
by: Koster | last post by:
Hi folks, As I understand it, amongst other things, the comma operator may be used to cause any number of expressions to be evaluated (who's results are thrown away except the last) where only one is expected, without the use of braces. So if (condition) i = 0, j = 1; causes both i = 0 and j = 1 expressions to be evaluated if condition evaluates to true. So far just making sure my understanding of the comma
11
2392
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal state\n"), TRUE) : \ (state = newstate, FALSE) This macro is called like this: setState(state, ST_Used);
4
2202
by: G Patel | last post by:
Hi, I've read a book on C, and I understand how comma operators work, but my book didn't say that the comma operators between function arguments were not really comma operators (even though it seems obvious to me that comma operators would serve no purpose between function arguments). As per C, are those commas in function argument lists the same comma operators? Also, are the =s used in initializations the same as any other
21
3050
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as opposed to what is mentioned in precedence table? Also, with comma operator. consider,
1
2477
by: CJK | last post by:
this is what i have so far: #include <iostream> #include <string> #include <vector> #include <fstream> using namespace std; class Person {
15
2637
by: Lighter | last post by:
In 5.3.3.4 of the standard, the standard provides that "The lvalue-to- rvalue(4.1), array-to-pointer(4.2),and function-to-pointer(4.3) standard conversions are not applied to the operand of sizeof." I think this rule is easy to understand. Because I can find the contexts of applying the rule as follows. (1) int* p = 0; int b1 = sizeof(*p); // OK, b1 = 4, *p would not be evaluated.
0
9636
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
10306
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
10139
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
10075
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,...
0
8961
agi2029
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...
1
7485
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
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
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
3632
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.