Global scope in Arduino ?

SCOPE
Just to make it worse, any variables you toss around and manipulate throughout your program have scope, which determines when they exist, and contain valid values. Scope may be global, local to a function, or local to any { block of code }
If you access a variable outside of it's valid scope, you'll get a compiler error.

I did not want to put this in "tutorials" , but have to ask.
Is term "global variable" in Arduino really global or just "local" in main(); ?

Cheers

Global, not local to main.

How could it be otherwise?

Function definitions cannot be nested.

TolpuddleSartre:
Function definitions cannot be nested.

sure they can...

int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

void setup() {
  Serial.begin(9600);
  auto funct = [&]() {
    for (auto& a : array) {
      auto square = [&a]() {
        Serial.print(F("initial a:\t"));
        Serial.println(a);
        a = a*a;
      };
      square();
    };
  };
  funct();
  Serial.println();
  for (auto a :array) {
    Serial.print(F("updated a:\t"));
    Serial.println(a);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

Those are lambda functions or anonymous functions.

loop and setup are clearly not anonymous.

I suspect you know this, but are just trying to look clever, but failing badly.

TolpuddleSartre:
Those are lambda functions oranonymous functions.

those lambda functions are neither oranonymous or anonymous.

they have names...

funct()

and

square()

TolpuddleSartre:
I suspect you know this, but are just trying to look clever, but failing badly.

I suspect that your C++ knowledge is what's "failing" (your word, not mine).

And embedded 'inline' function definitions are confusing to read / debug - and possibly scramble memory faster than a Kenwood Chef.

lastchancename:
And embedded 'inline' function definitions are confusing to read...

I'm sure you don't mean inline.

If you don't know the language, yes I'm sure you are correct.

lastchancename:
...and possibly scramble memory faster than a Kenwood Chef.

I'm not sure what that means... A lambda is managed on the stack like any other function.

Nonetheless, functions may certainly be nested in C++.

BulldogLowell:
those lambda functions are neither oranonymous or anonymous.

they have names...

funct()

and

square()

I suspect that your C++ knowledge is what's "failing" (your word, not mine).

I believe that the references to the anonymous functions are called "funct" and "square".
It's a subtle distinction, but an important one.

TolpuddleSartre:
I believe that the references to the anonymous functions are called "funct" and "square".
It's a subtle distinction, but an important one.

yes...

except that does not distinguish them. Just consider main, setup, and loop.

They are all pointers to a function.

funct and square just happen to have scope local to setup().

EDIT:

consider this equivalent code:

int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

void setup() {
  Serial.begin(9600);
  void(*funct)(void) = [&]() {
    for (auto& a : array) {
      auto square = [&a]() {
        Serial.print(F("initial a:\t"));
        Serial.println(a);
        a = a*a;
      };
      square();
    };
  };
  funct();
  Serial.println();
  for (auto a :array) {
    Serial.print(F("updated a:\t"));
    Serial.println(a);
  }
}

Setup() and Loop() are CALLED from the (unseen) main() function; they are NOT defined inside the main() scope.

[automatically typed pointers to lambda functions]

Whee! Congratulations!
You know more C++ than most arduino programmers (or even C++ programmers) ever use or need; a feature not defined until C++11, and not enabled/present (for example) in Arduino 1.0.6

Thank you SO MUCH for helping to confuse the beginners!

(I mean, I do appreciate having "real" C++ programmers around to explain occasional C++ features and issues, this was not the thread to bring up such an obscure point.)

westfw:
Setup() and Loop() are CALLED from the (unseen) main() function; they are NOT defined inside the main() scope.

did someone say they were?

westfw:
(I mean, I do appreciate having "real" C++ programmers around to explain occasional C++ features and issues,

No, I just tried to de-bunk the bunk... I suppose you'll be admonishing poor @TolpuddleSartre as well?

All your hyperbole aside, the current IDE is 1.8.5, kind sir.

westfw:
this was not the thread to bring up such an obscure point.)

should I be checking in with you first?

I suppose you'll be admonishing poor @TolpuddleSartre as well?

Nah. "How could it be otherwise" is sort-of "typical level of rudeness" for the Arduino forums (sigh)...

his was not the thread to bring up such an obscure point.)

should I be checking in with you first?

I was hoping to inspire better judgement in the more knowledgeable contributors. "Know your audience."
If the original post indicates a confusion between "defined in" and "called from", it's not the time to bring up lambda functions.