Re: Question about GTK+ and timers

Hi Igor,

On Sat, 9 Apr 2011 00:14:45 -0700 you wrote:
> >   MyWordVal = buf[2] + ( buf[3] * 256 );  /* data stream is little endian */
> >
> > This is portable and clear to any future maintainer. The efficiency
> > loss is negligible.
> Is there any way to find out if the device is little- or big-endian?

Well, if it's not your own device then one might hope it comes with a
data sheet. Otherwise, you'll need to arrange to print out the raw hex
data that arrives and reverse-engineer it.

> Also, I believe that the device spit out raw data in forms of characters.

Raw data in what sense? I'd be surp... well, no, probably not surprised
but definitely appalled if it's just dumping its internal data
structure. For one thing, a serial link is not a reliable transport
layer and needs to have some form of synchronisation protocol.

> And I failed to produce the same result as I got on x86.

That may be surprising, but it may not. If you are relying on two
different compiler back-ends for different processors generating the
same exact layout of a struct then endian-ness isn't your only problem.

> But I want to know for sure.
> And the code for the big-endian will look like:
> MyWordVal = buf[3] + ( buf[2] * 256 );
> right?

Yes, that's right. But remember this is the _data_stream_ endian that
you care about here, not the processor.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]