[sdiy] Pointers in C

Jay Vaughan jayv at synth.net
Sat Dec 31 18:19:48 CET 2011


Plus a union with bit field aliases is almost self documenting .. No thorny &/&& bugs to write.

;
--
seclorum 

On Dec 31, 2011, at 18:05, "Colin f" <colin at colinfraser.com> wrote:

> 
>> 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
> 
> 
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy



More information about the Synth-diy mailing list