What's the area outside of setup() and loop() called?

Or does it even have a name?

If it does, does it have different names for the part "above" setup(), "between" setup() and loop() and "below" loop()?

//
// what's this area called?
//

void setup()
{
}

//
// what's this area called?
//

void loop()
{
}

//
// what's this area called?
//

Never really thought about it but it would be logical to call it global (space)...

Both setup() and loop() are functions. As far as the compiler is concerned they are no different from any other function you might create.

The order in which you write functions (including loop() and setup() ) does not matter because the Arduino IDE creates function prototypes in the background to make things easy for you. Consequently the ideas of "before setup()" or "between setup() and loop()" are not meaningful.

What you need to take into account is that some things must be done outside of any function - such as declaring global variables or defining a function, And other things must happen inside a function - such as your program code and the definition of local variables.

...R

Preamble?

If an entity declared outside any block has global scope, then maybe that is what we should call it "global scope" or "global"

Except if it's declared outside of any function but with 'static' modifier. Then it's only 'Global' for that .cpp file.

Static area. In this example:

int a;
static int b;

void foo() {
  static int c;
}

Variables a, b, and c are all static. The are each assigned a spot in the executable image, and they keep that identity for the life of the sketch.

In this example:

void foo() {
  bar();
  baz();
}

void bar() {
  baz();
}

void baz() {
  int x;
  
}

x is an 'auto' or 'stack' variable. It is allocated space on the stack when a function is called, and where that space is varies according to the current state of the stack. It only 'lives' for the life of the function. Each time the function is called, it is uninitialized, which means that its value will be whatever garbage happened to have been left on the stack last time the memory there was used.

Let's call it 'The Ether' :wink:

//

// what's this area called?
//

A comment? White space? There is no particular name for white space outside a function (or indeed, inside a function).

If you were to put a variable there you might ask what that was called. And I might answer "a variable at global scope".

Its called Montana.

Sheesh, I thought everyone knew that.

-jim lee

It is called 'namespace scope'. Unless you explicitly declare a namespace, the namespace of the variable/function is in a global namespace, hence the name global (even though there is little really global about it with regards to a multi file app).

You'll see people familiar with other languages calling it "file scope" or "global scope".

int j = 4;  //Namespace scope

void func(){

  int j = 6;  //Block scope

  Serial.print( j );  //Print local j
  Serial.print( ::j ); //Print global j

  A_Label:   //Function scope

}

jimLee:
Its called Montana.

Sheesh, I thought everyone knew that.

LOL

...R

jimLee:
Its called Montana.

Sheesh, I thought everyone knew that.

-jim lee

The white area at the top is called Canada.

Translation unit. (Module in better structured languages.). However, setup and loop are included.

(Lots of karma for geographic analogies.)