[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-sparc
Subject:    Re: prevention of memory alignment issues?
From:       William Ahern <william () 25thandClement ! com>
Date:       2007-11-17 0:40:18
Message-ID: 20071117004017.GA20102 () wilbur ! 25thandClement ! com
[Download RAW message or body]

On Sat, Nov 17, 2007 at 01:01:47AM +0100, Markus Lude wrote:
> Hello,
> I would like to know how you take care of memory alignment in C. First
> idea is to reorder struct entries if possible. But why should oneself
> need to do this. Isn't this the work for a compiler? Is there some
> compiler switch or parameter so that the compiler could do the
> alignment? Or are there one to prevent the compiler from doing this? As
> a kind of last resort one could pad structs to align the entries by
> hand, but is this really the solution?
> 
> Any hint appreciated.
> 

The compiler _does_ take care of this. You're likely abusing the type
system. You very rarely ever need to cast object types in C. The common
exception is dealing with const qualifiers.

If you're treating your objects like just a bunch of bytes, then you're not
using C the way it was meant to be used. Some architectures, like x86, are
more forgiving when you abuse the system; SPARC, less so, as you seem to
have discovered. This is one of the reasons why SPARC is a better
environment for programming in C.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic