M
Mark Piffer
Christian Bau said:The only non-portable part is that ((unsigned int) ptr) & 0x03 might
have nothing to do with the alignment of the pointer at all.
char* p = ...;
p -= ((unsigned int) p) & 0x3;
will subtract a value from 0 to 3 from p, and in most implementations p
will be aligned to a multiple of four bytes afterwards.
I was under the impression (from 6.3.2.3/6) that this is undefined
behaviour as soon as the pointer is not representable in an int (which
happens to be this way on the majority of architectures I know (16-Bit
uC)) . Is there some assumption that makes it implementation defined?
Mark
PS: of course the above would nevertheless work on all those
architectures.