Question about nRF24L01+ Tutorial

Hi All.

So I just order some nRF24L01+ modules and thought I’d give @Robin2’s Tutorial a read. Very straight forward, nice job. But, something a little puzzling caught my eye:

The first example of TX code has:

char dataToSend[10] = "Message 0";

Makes sense to send a char array. But, invoking the library’s send() method shows:

rslt = radio.write( &dataToSend, sizeof(dataToSend) );

Now the library’s prototype for this method is:

bool write( const void* buf, uint8_t len );

So, I would have expected the call to be either:

rslt = radio.write( dataToSend, sizeof(dataToSend) );

OR

rslt = radio.write( &dataToSend[0], sizeof(dataToSend) );

I’ve been programming in ‘C’ for more than 30 years and have always used the former of these, but am willing to learn something new (to me). So, do ‘arrayName’ and ‘&arrayName’ resolve to the same thing when used as function arguments?

Thanks.

Yes.
If you run a test and print(dataToSend), print(&dataToSend), print(&dataToSend[0]), you should find that you get the same result for each.

DKWatson:
Yes.

Yup. I should have just tried it before posting. Took less time to test it than to write my original question:

char dog[10];
void printAddress(void *);

void setup() {
 Serial.begin(115200);
 delay(2000);
 Serial.println("Starting:");
 printAddress(dog);
 printAddress(&dog);

}

void loop() {
}

void printAddress(void *addr) {
 Serial.println((uint32_t) addr, HEX);
}

Serial Monitor:

Starting:
120
120

And, not just the Arduino Kiddie-IDE. Same in Eclipse/Sloeber.

Sorry for the bother.

No bother. I do my tests in Notepad++ so it's quick an easy.

DKWatson:
No bother. I do my tests in Notepad++ so it's quick an easy.

How do you get Notepad++ to compile and link code?

PaulS:
How do you get Notepad++ to compile and link code?

Define it all in a macro. I use four, GCC, GPP, AVRGCC and AVRGPP. You need the NppExec plug-in.

gfvalvo:
Makes sense to send a char array. But, invoking the library’s send() method shows:

rslt = radio.write( &dataToSend, sizeof(dataToSend) );

I chose to do it that way because that style also works if you are sending a single variable (an int, float etc) rather than an array.

I have no idea what benefit the C/C++ folks thought would accrue from having different ways to do the same thing - other than confusion.

...R

Probably something to do with backward/forward/sideways compatibility. Also, doing as Robin suggests helps down the road when debugging as you know what it is you're passing.