error: invalid operands to binary &

M

muthu

In the following code it gives the error "error: invalid operands to
binary &"
Why it is happening

#include <signal.h>
#include <errno.h>

#define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG)
/* <signal.h> usually defines NSIG to include signal number 0 */

int
sigaddset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set |= 1 << (signo - 1); // error
return(0);
}

int
sigdelset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set &= ~(1 << (signo - 1)); // error
return(0);
}

int
sigismember(const sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

return( (*set & (1 << (signo - 1))) != 0 ); //error
}

please give me the solution


With Regards,
Sureshlingam
 
A

ankisharma

muthu said:
In the following code it gives the error "error: invalid operands to
binary &"
Why it is happening

#include <signal.h>
#include <errno.h>

#define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG)
/* <signal.h> usually defines NSIG to include signal number 0 */

int
sigaddset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set |= 1 << (signo - 1); // error
return(0);
}

int
sigdelset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set &= ~(1 << (signo - 1)); // error
return(0);
}

int
sigismember(const sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

return( (*set & (1 << (signo - 1))) != 0 ); //error
}

please give me the solution


With Regards,
Sureshlingam

I suppose problem is with sigset_t data type because this could be
implemented as integer type or a strucure type. In your case it seems
that it is defined as a structure.
 
S

spibou

muthu said:
In the following code it gives the error "error: invalid operands to
binary &"
Why it is happening

#include <signal.h>
#include <errno.h>

#define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG)
/* <signal.h> usually defines NSIG to include signal number 0 */

int
sigaddset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set |= 1 << (signo - 1); // error
return(0);
}

int
sigdelset(sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

*set &= ~(1 << (signo - 1)); // error
return(0);
}

int
sigismember(const sigset_t *set, int signo)
{
if (SIGBAD(signo)) { errno = EINVAL; return(-1); }

return( (*set & (1 << (signo - 1))) != 0 ); //error
}

please give me the solution


With Regards,
Sureshlingam

*set is of type sigset_t which on my system is a structure.
You cannot apply the binary operators to structures. But
to be sure check how sigset_t is defined on your system.

Spiros Bousbouras
 
L

lawrence.jones

*set is of type sigset_t which on my system is a structure.
You cannot apply the binary operators to structures.

You need to use sigaddset(), sigdelset(), and friends to manipulate a
sigset_t.

-Larry Jones

Monopoly is more fun when you make your own Chance cards. -- Calvin
 
K

Keith Thompson

You need to use sigaddset(), sigdelset(), and friends to manipulate a
sigset_t.

And if you have more questions about these functions, you need to ask
elsewhere, probably in comp.unix.programmer. (This is addressed to
the OP, not to spibou or lawrence.jones.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top