Article 6TB0F Esoteric: Learn about Structure Packing and Padding

Esoteric: Learn about Structure Packing and Padding

by
hubie
from SoylentNews on (#6TB0F)

ElizabethGreene writes:

Eric Raymond has a lovely essay here: http://www.catb.org/esr/structure-packing/ that describes some non-intuitive behavior in how compilers assemble structures in memory. The default is to pad structures out with empty bytes to align data types around arbitrary byte boundaries for similarly non-intuitive reasons.

If you don't immediately understand why this struct is 12 or 16 bytes long, it's worth reading.

struct Foo {
char *p; /* 4 or 8 bytes */
char c; /* 1 byte */
int x; /* 4 bytes */
}

Original Submission

Read more of this story at SoylentNews.

External Content
Source RSS or Atom Feed
Feed Location https://soylentnews.org/index.rss
Feed Title SoylentNews
Feed Link https://soylentnews.org/
Feed Copyright Copyright 2014, SoylentNews
Reply 0 comments