3 ms·
> As for alignment guarantee by the language: your own example code uses pointer arithmetic to conjure up a class out of thin air that is overlaid over other me
by MaulingMonkey 7y ago
> As for alignment guarantee by the language: your own example code uses pointer arithmetic to conjure up a class out of thin air that is overlaid over other memory and thus has the improper alignment you're exploiting. That demonstrates how little faith you are allowed to have in the alignment of an instance of your type if you didn't allocate it yourself.
I forgot to point out in my other reply: -fsanitize=undefined immediately catches this, and gives me the exact source file / line number of the bug. So there are ways to convince yourself you're mostly doing the right thing.
EDIT: Scroll up to the first error in https://wandbox.org/permlink/q0mxk5DViIVs2GBl https://wandbox.org/permlink/q0mxk5DViIVs2GBl if you want to see an example.