Hi Community !!
the structure pulse ist defined as follows:
struct _pulse {
_Uint16t type;
_Uint16t subtype;
_Int8t code;
_Uint8t zero[3];
union sigval value;
_Int32t scoid;
};
…
and I want to make an assignment like this
struct _pulse pulse;
if(pulse.value==1)
{
something important
}
this never works.
please give me an solution for this member to do this.
Thank you !!!
mario
February 7, 2006, 2:29pm
2
Value is a union, what you are doing is exactly like trying to do
struct test {
int i;
int b;
};
struct test mytest;
if ( mytest ==1 ) // would you expect this to work
{
}
Yes; if this were C++ and there were a header file (not shown) that included the following definition:
bool operator==(struct test &lh, int rh)
{
return (lh.i == rh);
}
Thank you mario and rgallen
no I’dont expect this to work
I’ve only try to make my problem viewable with bad englisch
so, this is the easiest way to do this.
But how to get access to the pulse value to
print a text message with switch case like
pulse value =1 pritnts Message: xyz
pulse value =2 prints Message: zyx
and so on. ???
Thank you
mario
February 8, 2006, 12:30pm
5
struct _pulse pulse;
if(pulse.value.sigint ==1 )
{
something important
}
else if(pulse.value.sigint ==2 )
{
something even more important
}
Thank you mario great this works!
I’ve look the header signal.h where the sival union is defined.
mario
February 8, 2006, 6:42pm
7
Or you can write a C++ pulse class To be able to do
if ( pulse == 1 )
{
}
LOL!