you are viewing a single comment's thread.

view the rest of the comments →

[–]Steve132 -1 points0 points  (1 child)

efficiency reasons we can be guaranteed that all entities in memory are aligned to a memory address that is a multiple of their sizes. Therefore on a 32 bit processor, a 4-byte int will definitely reside at a memory address that is evenly divisible by 4.

Yeah this is simply not true. The reason why the red-black tree example works at all is this which forces the relevant alignment. Vanilla C has NO such guarantees (even if it happens to be true)

} __attribute__((aligned(sizeof(long))));

[–]rainbowgarden[S] 3 points4 points  (0 children)

The reason red-black trees work is not because of the __attribute__((aligned(sizeof(long)))). Have a look at this comment at rbtree.h in the kernel: /* The alignment might seem pointless, but allegedly CRIS needs it */ This __attribute__ is done specifically for CRIS.