@frogandtoad So just reviewed by reference and by ptr, in the c++ manual. Apparently it is a compiler convenience to pass by reference but at the end of the day it is still passed by ptr. It is just that by reference allows the compiler to have a clearer understanding and to do addition checks on the validity of the code (like not being able to pass a NULL ptr by mistake). I do agree that in c++ one should use by reference whenever possible.
Pat Wicker (Portland, OR, USA)
OK, I'm confused, I always thought by reference was just a fancy way of saying "by ptr". Can you clarify the difference?
Sure:
void passByPointer(int* array) { } void passByreference(int (&array)[10]) { } void setup() { Serial.begin(9600); int myArray1[10]; int myArray2[20]; passByPointer(myArray1); passByreference(myArray1); passByPointer(myArray2); // Will not compile - Reference attempt to bind to incorrect size //passByreference(myArray2); }
Both functions can directly manipulate the array, but the C++ with reference is safer because it won't allow you to bind at compile time to a different size arry, stopping you from just passing in old any pointer by value, of which the content it points to can still be manipulated.
@frogandtoad So just reviewed by reference and by ptr, in the c++ manual. Apparently it is a compiler convenience to pass by reference but at the end of the day it is still passed by ptr. It is just that by reference allows the compiler to have a clearer understanding and to do addition checks on the validity of the code (like not being able to pass a NULL ptr by mistake). I do agree that in c++ one should use by reference whenever possible.
I don't know of any manual that says "pass by pointer". Although I understand what is trying to be conveyed, but a pointer is passed by value in C, or by value or reference in C++... there really is a difference in both functionality and terminology, as they are not the same thing and should not be assumed to be so.
You are correct as well.
And again, more noise. Right or wrong un-necessary noise that was not needed for the original posters question. You apparently are one of the ones that have to be right, no matter what, and make it know. Less is more sometimes. EOC.
Thank you kindly for that info. I've once seen someone write and implement their own version of the loop() function using a C programming int main {} structure, but never knew how they did what they did, and never looked further into it. I have so much to learn.
C++ and Arduino are NOT my strongholds by any measure...at those I suck. I do enjoy digging into bit-level pushin' and poppin' using C and Assembler, though. Me likes.
I'm good on the F macro for strings in flash memory. Another handy little trick.
Nice to meet you, frogandtoad!
I'm actually doing a Wiring type library for the 16F Pic's now out of boredom. Making it very light and just for fun really. I will probably skip the setup and loop functions 🙂 I have a blink program working now (pinMode and digitalWrite) and will do Digi read and the analog read soon. I can hear engineers crying and laughing all over the world now!
Scott
@frogandtoad I'm pretty sure you would find it to be the same thing in the assembly language. By reference just gives the compiler some clues for what kind of mistakes to prevent.
Pat Wicker (Portland, OR, USA)
Sorry, but I'm not exactly sure what you're referring to when you say "it" would be the same thing in the assembly language?