1. c type short int to euphoria int conversion
- Posted by cp Dec 06, 2008
- 1044 views
- Last edited Dec 07, 2008
I'm calling a c api that returns a boolean value (defined as a unsigned short int in the c header file) and I assign this to a euphoria integer. Since the boolean value is an error code either a 1 or 0. When I test the Euphoria integer I don't get a 1 but some other value. Is it safe for me to assume that anything other than a 0 is the same as a 1 in the short int I retrieve and that if the short int is a zero it will still be a zero when assigned to eu integer. Or am I way off and there is a better way. Thanks
2. Re: c type short int to euphoria int conversion
- Posted by mattlewis (admin) Dec 06, 2008
- 1102 views
- Last edited Dec 07, 2008
I'm calling a c api that returns a boolean value (defined as a unsigned short int in the c header file) and I assign this to a euphoria integer. Since the boolean value is an error code either a 1 or 0. When I test the Euphoria integer I don't get a 1 but some other value. Is it safe for me to assume that anything other than a 0 is the same as a 1 in the short int I retrieve and that if the short int is a zero it will still be a zero when assigned to eu integer. Or am I way off and there is a better way. Thanks
C is similar to euphoria in that 0 is considered false, and any other value is true. A short int is a 16 bit value, which is smaller than a euphoria integer, so you're not losing any information.
What value do you get in the return? Is it always the same? Do you have access to the source code for whatever library you're calling?
Matt
3. Re: c type short int to euphoria int conversion
- Posted by cp Dec 08, 2008
- 1069 views
- Last edited Dec 09, 2008
The eu integer value is 91 and I get the same value every time. I don't have access to the source code, but I do have access to the c header file for the library.
4. Re: c type short int to euphoria int conversion
- Posted by bernie Dec 09, 2008
- 1095 views
The eu integer value is 91 and I get the same value every time. I don't have access to the source code, but I do have access to the c header file for the library.
I'm calling a c api that returns a boolean value (defined as a unsigned short int in the c header file)
BOOLEAN is a SIGNED value not an UNSIGNED value.
5. Re: c type short int to euphoria int conversion
- Posted by cp Dec 09, 2008
- 1021 views
here is the definition in the api header:
typedef unsigned short TM1_BOOL; boolean flag
6. Re: c type short int to euphoria int conversion
- Posted by mattlewis (admin) Dec 09, 2008
- 1011 views
here is the definition in the api header:
typedef unsigned short TM1_BOOL; boolean flag
Yup, that's a 16-bit value. I'd assume that any zero value is false, and any non-zero value is true.
Matt