[sdiy] Pointers in C
Colin f
colin at colinfraser.com
Sat Dec 31 18:05:10 CET 2011
> I'd just dereference the 32bit pointer, and get the
> individual bytes by bit masking and shifting instead.
> i.e.
>
> unsigned long allbytes = *my_unsigned_long_ptr; unsigned char
> LSByte = allbytes && 0x0ff; unsigned char secondbyte =
> (allbytes && 0x0ff00)>>8; unsigned char thirdbyte = (allbytes
> && 0x0ff0000L)>>16; unsigned char MSByte = (allbytes &&
> 0x0ff000000L)>>24;
>
> In my opinion this gives much less confusion with endianess...
It gives rather more confusion between & and && though ;-)
You want bitwise rather than logical.
Cheers,
Colin f
More information about the Synth-diy
mailing list