Re: C programming on ARM



Paul Keinanen wrote:
CBFalconer <cbfalconer@xxxxxxxxx> wrote:
Jim Relsh wrote:

.... snip ...

Or cast to the correct type (if you are sure and know what
you're doing).

Caution. Most pointer casts are implementation defined. The
exception is casting to and from void*, and from void* back to
the original type.

In which case would an arbitrary pointer casting be a problem ?

The only situation I can think of is for instance some DSP with
24 bit addressable unit or some old 36 bit mainframe, in which
for instance a char* would require the memory word and also
information which quarter word is referenced.

With any byte addressable architecture, a pointer is just a
pointer.

No. Pointers also carry (or imply) information about the object
type, including alignment requirements. Misaligned access to an
item can cause all sorts of unwelcome reactions.

One thing you can do is cast a pointer to an unsigned char*. But
not the reverse. Note that you can't dereference a void*.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... You can't do pointer arithmetic on a void* value. ... qsort behaves in a manner consistent with its specification. ... actually works as advertised...but doesn't mean that the cast is ...
    (comp.lang.c)
  • Re: Common misconceptions about C (C95)
    ... Cast it to suitable type instead. ... The void and void * types come from C++ which has a better rules for them. ... object as an array of bytes (unsigned char *). ... it's okay for that pointer to be a pointer to unsigned char *. ...
    (comp.lang.c)
  • Re: [PATCH] [0/9] Use 64bit x86 machine check code for 32bit too
    ... warning: passing argument 2 of ‘strict_strtoull’ makes integer from pointer without a cast ...
    (Linux-Kernel)
  • Re: dynamic_cast does not work as specified
    ... then p is a pointer to an object of type SubThing. ... SubThing* via a C-style cast. ... virtual void ShowPURE; ... type-id must be a derived class of expression [note that the simple explanation could be ...
    (microsoft.public.vc.mfc)
  • Re: [RFC] timers, pointers to functions and type safety
    ... * they have callback of type void ... callback is called by the code that even in theory has no ... cast to unsigned long and cast back in the callback. ... number - not a pointer cast to unsigned long, not an index in array, etc. ...
    (Linux-Kernel)