🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.protocols.tcp-ip
Article #8037

Re: Help about this code?

#8037
From: Clyde Smith-Stubbs
Date: Tue, 26 Dec 1995 22:39
57 lines
2568 bytes
On 26 Dec 1995 22:06:38 GMT, e8927426@fbma.tuwien.ac.at (Seda Oezses)
wrote:


>	STSHORT(10, buff + 1); 
>	i = LDSHORT(buff + 1);
>	printf("%d\n", i);
>
>	- On a SUN SPARCclasic (Solaris 2.4) the result was a Bus error.
>	- On a DECStation 5500 (ULTRIX 4.4) program run and printed 10 but with a
>	  message "Fixed up unaligned data access for pid 25977 (a.out) at pc 0x400678".
>	- On a RISC/6000 (AIX ??) program run without an error or warning.
>
>	
>Do you have any idea about why this little code produce such different results on
>different processors?

Sure. You are using typecasting to force a word or longer reference to
an odd memory address. Some processors are incapable of accessing
things bigger than a byte on an odd address, while others can do so,
but take a performance hit. It sounds like Ultrix has trapped the odd
address exception and fudged it for you - are those DEC people kind or
foolhardy? 

In general you should not try and do things like this. If you
absolutely must insert or extract word quantities on randomly aligned
addresses, you should do so by accessing a byte at a time and
reassembling the data, or by storing a byte at a time, e.g.

put2(unsigned char * ptr, unsigned short val)
{
	*ptr = val & 0xFF;
	ptr[1] = val >> 8;
}

but note that this is assuming little-endian byte ordering.

Happy New Year, Clyde
>
>
>
>
>--
>
>        ("\''/").___..--'''"-._
>       `9_ 9  )   `-.  (     ).`-.__.`)     S  E  D  A   O  Z  S  E  S
>       (_Y_.)'  ._   )  `._ `. ``-..-'
>     _..`--'_..-_/  /--'_.' .'              e8927426@fbma.tuwien.ac.at
>    (il).-''  ((i).'  ((i.-'
>

 Clyde Smith-Stubbs       | HI-TECH Software,       | Voice: +61 7 3300 5011
 clyde@hitech.com.au      | P.O. Box 103, Alderley, | Fax:   +61 7 3300 5246
http://www.hitech.com.au  | QLD, 4051, AUSTRALIA.   | BBS:   +61 7 3300 5235
----------------------------------------------------------------------------
FREE! Download our shareware (FREE for noncommercial use) MS-DOS C Compiler!
             Point your Web browser at http://www.hitech.com.au/
Technical Details
Message-ID: <30e07870.474890112@news.bne.aone.net.au>
Path: arc1-ca.pugleaf.net!news.mel.aone.net.au!usenet
References: <4bprle$n2k@news.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mel.aone.net.au!usenet
From: clyde@hitech.com.au (Clyde Smith-Stubbs)
Newsgroups: comp.protocols.tcp-ip,comp.lang.c
Subject: Re: Help about this code?
Date: Tue, 26 Dec 1995 22:39:27 GMT
Organization: HI-TECH Software
Message-ID: <30e07870.474890112@news.bne.aone.net.au>
References: <4bprle$n2k@news.tuwien.ac.at>
Reply-To: clyde@hitech.com.au
NNTP-Posting-Host: skyhawk.hitech.com.au
X-Newsreader: Forte Agent .99c/16.141