Re: Converting a long long to an int8.
Posted in 2004
I'm finding it hard to believe that despite informix provides an int8 dbase
and ESQL/C type, there is not straight fwd way to get an 8 byte 'C' number
into it !!!!
Oh well!
I'll have a go with the suggestions, many thanks
Andrew H.
----- Forwarded by Andrew Hardy/MAIN/MC1 on 15/07/2004 09:02 -----
|---------+---------------------------->
| | Jonathan Leffler |
| | <jleffler@earthli|
| | nk.net> |
| | Sent by: |
| | owner-informix-li|
| | st@iiug.org |
| | |
| | |
| | 15/07/2004 06:08 |
| | Please respond to|
| | Jonathan Leffler |
| | |
|---------+---------------------------->
>--------------------------------------------------------------------------------------------------------------------------------------------------|
| |
| To: informix-list@iiug.org |
| cc: |
| Subject: Re: Converting a long long to an int8. |
>--------------------------------------------------------------------------------------------------------------------------------------------------|
Andrew Hardy wrote:
> My guide seems to tell me the functions to convert to an int8 the types
> long and double, but not a long long, which on our machine is the type
for
> an 8 byte value.
>
> I actually want to store an unsigned long long. I don't mind if ifx
thinks
> it's signed or shows it as signed in dbaccess or if I have to cast it to
> signed tpo store it so long as when I get it back internally it still has
> the same bits set.
>
> But I can't seem to see the function to do this.
>
> Should i be using something other than an int8 ? A serial8 ?? Or
> something. Which function do I use ?
You need to write your own - until further notice. You could try
checking for undocumented functions starting ifx_int8, but...
The structure is documented in int8.h. Your sign bit is in the sign
field; one of the two 32-bit unsigned integers contains 31 bits, the
other 32 bits. You can therefore reassemble them into a 64-bit long
using:
long long ifx_int8tolonglong(ifx_int8_t *in)
{
long long out = in->data[0] << 32 | in->data[1];
if (in->sign < 0)
out = - out;
return(out);
}
You'd need to experiment to see whether the shift is 32 or 31, and
whether element 0 or element 1 is the more significant. I'm also
ignoring NULL.
The inverse conversion is not very much harder, of course.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
sending to informix-list