[sdiy] Pointers in C
Richard Wentk
richard at wentk.com
Sat Dec 31 13:48:02 CET 2011
Pointers include (sizeof) information, so - if I remember correctly - ++ always adds the size of the data type.
This may not be what you want.
If you want to access individual bytes, you can just add 1 (or 2 or 3...) to the pointer.
See also
http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/pointer.html
Richard
On 31 Dec 2011, at 11:42, Paul Maddox <yo at vacoloco.net> wrote:
> All,
>
> Pointers have always confused me, though I'm getting better slowly.
>
> But I have a question, if I have a pointer to an unsigned long int (32bits) and I want to access it as four unsigned chars, do I just read a char and increase the pointer? for example;
>
> int *my_ptr = my_unsigned_long_int;
> unsigned char FirstByte = *my_ptr;
> my_ptr++;
> unsigned char SecondByte = *my_ptr;
> my_ptr++;
> unsigned char ThirdByte = *my_ptr;
> my_ptr++;
> unsigned char FourthByte = *my_ptr;
>
> or am I nuts?
>
> Paul
>
> ______________________________________
> VacoLoco
>
> http://VacoLoco.net
>
>
>
>
> _______________________________________________
> 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