Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Struct Alignment

Reply
Thread Tools

Re: Struct Alignment

 
 
Jack Klein
Guest
Posts: n/a
 
      08-04-2003
On Mon, 04 Aug 2003 01:50:19 +1000, Andre <(E-Mail Removed)>
wrote in comp.lang.c:

> Why does gcc (or any C compiler for that matter) align structs on double
> word boundaries? And why should we align variables inside structs? One
> clear advantage could be cache utilization but isn't that possible even
> without alignment? Thanks
>
> -Andre


There are some architectures that gcc compiles for (ARM for sure) that
actually require specific alignment for specific data types.
Accessing data at a misaligned address can generate a trap that kills
the program.

There are other architectures that actually just ignore one or more
low bits when accessing certain types, acting as if they were 0 even
if they are not.

As to why gcc decides on any particular alignment for any particular
hardware platform, ask in a gcc group. It is not a language issue.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Alignment on Struct and Global Variable? Bryan Parkoff C++ 0 04-02-2005 02:32 AM
struct and union alignment S.Tobias C Programming 67 10-04-2004 07:27 AM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
Re: Struct Alignment Eric G. C Programming 2 08-04-2003 09:30 PM



Advertisments