I'm studying C language.
I was reading the source code for zsh and there was something I didn't understand.
ZSH-THE Z SHELL
/*If not a POSIX machine, then we create your*
* own POSIX style signal sets functions.*/
# ifndef POSIX_SIGNALS
# define sigemptyset(s)(*(s)=0)
# define sigfillset(s)(*(s)=~(sigset_t)0,0)
# define sigaddset(s,n)(*(s)|=(1<<((n)-1)), 0)
# define sigdelset(s,n)(*(s)&=~(1<<((n)-1)), 0)
# define sigismember(s,n)((*(s)&(1<<(n)-1))!=0)
# endif /* ifndef POSIX_SIGNALS*/
/**/
sigset_t signal_mask(int sig)
{
sigset_tset;
sigmptyset (&set);
if(sig)
sigaddset(&set,sig);
return set;
}
I would like to know what the comma operator of the macro function sigaddset defined in this define is doing.
sigaddset(s,n)(*(s)|=(1<<((n)-1)), 0)
(1) 1<<(n)-1)
② *(s)=*(s)|(Result value of formula 1)
③ 0
#Do nothing?
The role of the last comma operator is unknown.
Is my expression in the wrong order of deployment?
Thank you for your cooperation.
c
The ,
operator evaluates the expression on the left, then abandons the result and evaluates the expression on the right.
int x = sigaddset(s,n);
If ,0
is not present, the value of *s
is stored, but ,0
is added to store 0
.The return value of the function may indicate success.
I think that sigaddset has a function specification that returns 0 if successful and -1 if error.
© 2024 OneMinuteCode. All rights reserved.