[sdiy] Pointers in C

Gordon JC Pearce gordonjcp at gjcp.net
Sat Dec 31 12:55:17 CET 2011


On Sat, 31 Dec 2011 11:42:41 +0000
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;

I think you can (ab)use a union for this, something like:

union myunion {
	unsigned long myvariable;
	struct {
		unsigned char byte1;
		unsigned char byte2;
		unsigned char byte3;
		unsigned char byte4;
	} mybytes;
}

-- 
Gordon JC Pearce MM0YEQ <gordonjcp at gjcp.net>



More information about the Synth-diy mailing list