a pointer is the combination of the address and the type of data there, that's why you see different types of pointers:
char* myString; // a pointer to a char (array)
int* value; // a pointer to an int16_t
gfvalvo:
...I'd guess that 'text' is an array of 'char'. If so, 'text' is already a pointer. I would think the call should be:
no.
the source is simple:
bool RF24::write(const void * buf, uint8_t len)
hmmm... what's that, a void pointer?
yes, in this case they are using a void or "typeless" pointer... so, to pass the char array (it seems in this case) you pass only the address of the pointer which essentially strips the type off of the pointer (all you need for a void pointer).
&text
so, like this:
const char test[] = "this is a test";
void setup()
{
Serial.begin(9600);
myFunct(&test);
}
void loop()
{
}
void myFunct(const void* vdPtr)
{
char* someArray; // creates a pointer to some char array
someArray = (char*)vdPtr; // cast the void pointer to a char* and assign it to someArray
Serial.print(someArray);
}
Why do this? you can then write() arrays of different types...
const char test[] = "this is a test";
const byte data[] = {0xff, 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed, 0x00};
void setup()
{
Serial.begin(9600);
myFunct(&test, sizeof(test));
myFunct(&data, sizeof(data));
}
void loop()
{
}
void myFunct(const void* vdPtr, size_t size)
{
char* someArray; // creates a pointer to some char array
someArray = (char*)vdPtr; //cast the void pointer to a char* and assign it to someArray
Serial.write(someArray, size);
Serial.write('\n');
}
powerful stuff...
EDITED:
Everything works correctly, I'm just curious as to why there is an "&" in front of "text".
what happens if you don't include the & operator? the parameter (pointer to char or pointer to byte) will be cast to a void pointer!
why use it at all? good programming technique!! displays that there is more behind what's going to happen... it begs any casual programmer to go look at the function!