* <- that is _not_ a "pointer"
That is an asterisk. It tells the compiler you want it to work with the _address_ of the specified variable of the specified type, not the _contents_ of the variable.
when you say
Code:
typedef struct
{
unsigned char red;
unsigned char blue;
unsigned char green;
}RGB;
you are creating a variable _type_. you can create any number of variables of type 'RGB'.
When you pass a variable of this type to another function, or procedure, it's faster and more effecient to pass it's _address_ (that is, where it resides in RAM), so that the function can manipulate the actual data indirectly.
And here is the specific difference:
Code:
void foo1(RGB); /* prototypes */
void foo2(RGB*);
int main(void);
int main(void)
{
RGB myRGBStruct;
myRGBStruct.red = 0xFF;
myRGBStruct.blue = 0xCC;
myRGBStruct.green = 0x00;
foo1(myRGBStruct); /* pass a copy of myRGBStruct to the func */
foo2(&myRGBStruct) /* pass the addressof the original myRGBStruct to the func */
return(0);
}
void foo1(RGB myRGB)
{
myRGB.blue = 0xEE;
} /* <- myRGB is _gone_ off th stack when we return */
/* from this procedure, so 'myRGBStruct' in main */
/* was not affected. */
void foo2(RGB *myRGB)
{
myRGB->red = 0xAA; /* myRGBStruct.red in main(), just got changed */
}