Appreciate all replies. I’ve done some initial reading about ‘forward declarations’. But so far come across no explanation why neither setup() nor loop() have a semicolon at their ends?
These are both actual functions, not declarations, yes? So…?
I thought the best way to describe a semicolon is the end of a 'statement'. A brace defines scope.
Since a brace defines the scope, when scope ends, it ends the statement. The semi colon is optional.
if (x) {
int a;
.
{
int a;
.
.
}
} else....
the inner bracket group specified the scope of it's 'a' variable...
I think the history of C may explain how these variations occurred... My first language was 'B', showing my age, and the semicolon was a required part of the statement. B was a 'typeless' language in that it was the machines 'word' size for everything.
B came about from the BCPL developed from Multics by Ken Thompson...I think.. it's been a year or two since I thought about it....
Here is a document from Dennis M. Ritchie, about the history of C and you can see how things were implemented and changed... I think he might know a little about what's happening back then...
When I write the code for setup() and loop() functions in my sketches, they have curly braces with no semicolon just like any other function in my code.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
myFunction();
}
void myFunction() {
Serial.println("In myFunction()");
}
setup(), loop(), and myFunction() all have the same form.
I know how to call it. If you look at my loop() implementation then you will see that I it contained such a call.
My reply was meant for the OP, @Terrypin, where he indicated that the implementation of his own functions have a different form than setup() and loop(). I was just pointing out that all of my function definitions have the same form. No matter if they are my own custom functions or the ones that Arduino requires.
Thanks, that and further links helped me to reach the simple solution I sought. Please correct me if my following conclusion is wrong:
In Arduino programming the two mandatory functions, setup() and loop(), are special defaults, thankfully inbuilt within the IDE. I assume they are presented in that inconsistent way for simplicity and immediate ease of use, awaiting user declaration.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
"BTW, there's no such terminology as a "mandatory function"
Nothing to do with 'terminology'. It's just a simple fact that all Arduino sketches must have two functions: setup() and loop(). That's what 'mandatory' means!