UKHeliBob:
I don't understand what you mean. Can you please provide a small example ?
Sure, that's easy to do. The buggie code below compiles without errors or warnings.
Arduino provides simplicity by throwing the hard learned rules of C and C++ out the window. This freedom from the rules comes at the cost of undetected errors. Actually, they're intentionally ignored.
This is not a complaint, just my observation of how the lack of rules can create incredibly bad programming habits that (IMO) can prevent many (most?) Arduino users from developing decent programming skills because they're never forced to understand the core, underlying language and just as importantly, the hardware. But hey, to keep things in perspective, you cannot ignore the success of the platform.
With respect to eliminating the rules, the quote the line from the Spiderman movie comes to mind: "With great power comes great responsibility".
IMO, you'll only find experienced C and C++ programmers being reasonably productive with the Arduino environment because they already understand the rules. If you don't believe me, I challenge you to find the phrases "prototype" or "type checking" in the Arduino language documentation. Please let me know if you find them anywhere outside of the forum, I've never seen those topics mentioned.
Oh, yeah, I know, I don't define reasonably productive. That's my just my belief. Don't feel the need to try and sway/move/change my opinion. I'm an old fart.
PS: Compiled in 1.8.3 Mac and tested on clone Uno.
void setup() {
int varInt;
byte varByte;
Serial.begin(115200);
Serial.println("");
varInt = 0x2710;
// prints 0x2710, CORRECT
Serial.println(varInt,HEX);
varByte = 0x64;
Serial.println(varByte,HEX);
// prints 0x64, CORRECT
// fails queitly, C and C++ type checking would flag this
varByte = varInt;
// prints 0x10, INCORRECT okay for LSB but not expected value
Serial.println(varByte,HEX);
// fails queitly, C and C++ type checking would flag this
varInt = varByte;
// prints 0x10, CORRECT
Serial.println(varInt,HEX);
// no prototype required for forward reference, no warning or error
// C would return warning for incorrect calling type
// fails queitly for all issues
// function call prints 0x10 which is the LSB of 0x2710
// okay but not what the user expects
varInt = functionRetunsInt(varInt);
// prints 0x10, INCORRECT, 0x2AF8 expected
Serial.println(varByte,HEX);
// change the return type and this also fails quietly in a different way
// function call prints 0xE8 which is the LSB of 0x03E8
// which is coming directly from the routine without any addition being performed
// so the function behaves differently depending upon the assigned return type
varByte = functionRetunsInt(varInt);
// prints 0xE8, INCORRECT, 0x2AF8 expected
Serial.println(varByte,HEX);
}
void loop() {}
int functionRetunsInt(byte value) {
byte retVal;
int varInt = 0x3E8; // 1000 decimal
Serial.print("passed value = ");
Serial.println(value,HEX);
retVal += varInt;
return retVal;
}