Skip to Content.
Sympa Menu

freetds - Re: killer query

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: ZIGLIO Frediano <Frediano.Ziglio AT vodafoneomnitel.it>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: killer query
  • Date: Wed, 26 Jun 2002 11:39:00 +0200


>
> > This line
> > memcpy (&(any.u), src, sizeof(TDS_UNIQUE));
> >
> > Do not work for bigendian machine
> >
> > freddy77
>
> Hi Freddy,
>
> Nice to have someone else in the European Time Zone!
> That's my line of code...can you explain further what's wrong ?
>
> Thanks,
>
> Bill
>
src is a TDS_CHAR* (a raw pointer) and you copy it in a structure. If
structure is byte to byte the same you copy correctly data but on different
architectures this fail.
Consider this structure:

typedef struct Test
{
TDS_INT num;
} Test;

and following octets (assuming TDS_INT 32bit):
*src = 01 02 03 04 (not C code...)
doing
Test tst;
memcpy(&tst, src, sizeof(tst));
Will produce tst.num == 0x4030201 on little endian machine (such as intel)
and tst.num == 0x1020304 on big endian machine (such as sparc).
Also in some architecture you can have TDS_INT 64bit (alpha) having garbage
and other problems...

Best solution is to build structure, such as

tst.num = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);

(a macro/inline function and some optimization for every platform is
preferred)
This should work on every architecture (even quantic, where machine do not
handle bit very simply)

freddy77

=================================
"STRICTLY PERSONAL AND CONFIDENTIAL

This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.
The contents of this message that do not relate to the official business of
our company shall be understood as neither given nor endorsed by it."

=================================




Archive powered by MHonArc 2.6.24.

Top of Page