TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Pascal Schmidt
from: Bo Simonsen
date: 2004-01-24 00:01:20
subject: Re: Big endian machines

PS> Hi Bo! :-)

Hi Pascal, 

 BS> Okay, but just to be scure, I will use Jasens fidoswap, I wonder if 
 BS> there should be any problems in that?

 PS> You still get to implement autodetection of the 
 PS> machine's native byteorder, and then only use fidoswap 
 PS> when it is needed.

On little endian machines it should just be defined as fido_swap(x)
with no action?

 PS> Or do something like this:

 PS> void swap16(uint16_t *orig)
 PS> {
 PS>     uint8_t x,y;

 PS>     x = *(uint8_t *) orig;
 PS>     y = *(((uint8_t *) orig)+1);

 PS>     *orig = x + y * 256;
 PS> }

 PS> That should work on both big and little endian machines, if *orig is
 PS> read from disk and is stored there in little endian byteorder.

Aha smart!

 PS> Note that all the parens in the y expression are important, don't leave
 PS> any off or change their scope.

I'll not.

Bo


--- Maximus/UNIX 3.03b
* Origin: The Night Express - Roennede, Dk (2:236/100)
SEEN-BY: 633/267 270
@PATH: 236/100 237/9 20/11 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.