Re: C programming on ARM
- From: "Wilco Dijkstra" <Wilco_dot_Dijkstra@xxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 10:47:30 GMT
"Grant Edwards" <grante@xxxxxxxx> wrote in message news:13q263sdle28k54@xxxxxxxxxxxxxxxxxxxxx
On 2008-01-31, Wilco Dijkstra <Wilco_dot_Dijkstra@xxxxxxxxxxxx> wrote:
"Grant Edwards" <grante@xxxxxxxx> wrote in message news:13q21msqkij3dbb@xxxxxxxxxxxxxxxxxxxxx
On 2008-01-30, Wilco Dijkstra <Wilco_dot_Dijkstra@xxxxxxxxxxxx> wrote:
Actually most architectures are byte addressable, including ARM,
True, but many of them (ARM, SPARC, MSP430, ...) have alignment
requirements for objects larger than 1 byte in size.
Byte addressability refers to the smallest unit of
addressability, not to the coursest.
I know.
so casting pointers just works.
I think the disconnect is in what you meant by "just works". We
assumed you meant it resulted in a pointer that could be
dereferences. Apparently you meant that it could be cast to
someother type, then cast back to the original type and result
in the same pointer?
OK, so I was a bit short on the explanation. I meant that pointers
contain no magic bits or other info besides the bit pattern of the
address. Therefore you can cast an integer to a pointer and
back, or a pointer to any other pointer type and back and you do
not lose a single bit of information. All this is guaranteed if you
have a byte addressable architecture, ie. pointer casting is safe.
Dereferencing pointers is something entirely different altogether.
Not all pointers can be dereferenced, think about the null pointer,
or pointers that point just beyond a variable (something C permits).
Also it is never a good idea to cast a pointer to a small object to
a larger one as you will corrupt memory if you access beyond the
original object. Natural alignment is just another thing to take into
account (however many compilers support unaligned types).
Wilco
.
- References:
- C programming on ARM
- From: aamer
- Re: C programming on ARM
- From: Arlet Ottens
- Re: C programming on ARM
- From: Jim Relsh
- Re: C programming on ARM
- From: CBFalconer
- Re: C programming on ARM
- From: Paul Keinanen
- Re: C programming on ARM
- From: Hans-Bernhard Bröker
- Re: C programming on ARM
- From: Wilco Dijkstra
- Re: C programming on ARM
- From: Grant Edwards
- Re: C programming on ARM
- From: Wilco Dijkstra
- Re: C programming on ARM
- From: Grant Edwards
- C programming on ARM
- Prev by Date: Re: C programming on ARM
- Next by Date: Re: C programming on ARM
- Previous by thread: Re: C programming on ARM
- Next by thread: Re: C programming on ARM
- Index(es):
Relevant Pages
|