I want to know what the comma operator of define sigaddset(s,n)(*(s)|=(1<<((n)-1)), 0) is doing.

Asked 2 years ago, Updated 2 years ago, 36 views

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

2022-09-30 15:01

2 Answers

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.


2022-09-30 15:01

I think that sigaddset has a function specification that returns 0 if successful and -1 if error.


2022-09-30 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.