3 comments

[ 5.2 ms ] story [ 13.0 ms ] thread

  struct fields {
    uint8_t f1;
    uint16_t f2;
    uint8_t f3;
  }
> What do you think the size of this structure is? It should be 4 bytes, right?

Of course not! Ever heard of this "memory alignment" thing? There even were architectures where accessing an unaligned int would get you SIGBUS (Solaris/SPARC was one, from what I remember). Have you never wondered where all the unix signals came from?

Yep memory alignment a terrible cancerous idea[1] left over from 80's/90's era RISC machines.

[1] Hey lets make the memory layout look like Swiss Cheeze and increase the pressure on the cache! It'll totally be faster!!!

I guess there are people who do not know about #pragma pack.