Re: Misc Qns...
From: Mark F. Haigh (mfhaigh_at_sbcglobal.ten)
Date: 12/17/03
- Next message: Kevin Goodsell: "Re: Why isn't this working correctly?"
- Previous message: Simon Biber: "Re: UTF-8 in char*"
- In reply to: Jack Klein: "Re: Misc Qns..."
- Next in thread: glen herrmannsfeldt: "Re: Misc Qns..."
- Reply: glen herrmannsfeldt: "Re: Misc Qns..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 17 Dec 2003 07:46:28 GMT
Jack Klein wrote:
> On Tue, 16 Dec 2003 16:00:20 GMT, Thomas Matthews
> <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> wrote in comp.lang.c:
>
>
>>Jin wrote:
>>
>>
>>>1. Will simply taking the address of a non-aligned variable (but not
>>> deferencing it) produce undefined behavior?
>>
>>Not according to the _Standard_. Alignment restrictions are an
>>implementation detail, not one of the standard. My understanding is
>>that accessing data that is not aligned will just take more fetches
>>by the processor.
>
>
> You are very, very wrong here. Some platforms, such as Intel x86,
> will perform additional memory cycles, to be sure.
>
> But there are at least two other types of responses in current
> architectures, particularly RISC and/or DSP:
>
> 1. The low bits of the pointer are merely ignored. On this type of
> architecture if you tried to access a 32 bit value at any of the
> addresses 0x1000, 0x1001, 0x1002, or 0x1003 would pick up the four
> bytes at 0x1000 through 0x1003 inclusive. Even if you expected trying
> to read a 32 bit value with a pointer containing 0x1003 to pick up
> that byte plus 0x1004, 0x1005, and 0x1006.
>
> 2. The processor platform performs automatic alignment checks and
> generates a trap or exception if a multi-byte object is accessed at an
> address with incorrect alignment. If there is an operating system
> involved, it generally terminates the program that did this with
> something called "sigbus" or some such.
>
#2 may also direct the trap or exception to a kernel handler that fixes
up the access with the expected results, using byte loads. Of course,
it's horrendously slow. It's sometimes used to help poorly written
(most often x86-centric) software limp along on things like ARM Linux
and such.
Mark F. Haigh
mfhaigh@sbcglobal.net
- Next message: Kevin Goodsell: "Re: Why isn't this working correctly?"
- Previous message: Simon Biber: "Re: UTF-8 in char*"
- In reply to: Jack Klein: "Re: Misc Qns..."
- Next in thread: glen herrmannsfeldt: "Re: Misc Qns..."
- Reply: glen herrmannsfeldt: "Re: Misc Qns..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|