Skip to main content
added 137 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

I'm used to this way from my desktop C++ programming practice:

int array[100] = {0};

I couldn't find any info on whether or not this construct works on Arduino.

The = {0} has no actual effect. It is the same as:

int array[100];

Uninitialized static / global variables, and variables explicitly initialized to 0, are placed in the .bss section of memory.

This section is initialized to 0 by the CRT (C Runtime) code (the startup code for the system).

The compiler is responsible for placing these variables in the .bss, but it is the job of the startup (CRT) code to initialize it to zero.

This is standard C operation and is not likely to ever change since it would break all sorts of things.

Note: this does NOT apply to local variables allocated on the stack. These must be initialized to 0 if you want them to start as 0.

I'm used to this way from my desktop C++ programming practice:

int array[100] = {0};

I couldn't find any info on whether or not this construct works on Arduino.

The = {0} has no actual effect. It is the same as:

int array[100];

Uninitialized static / global variables, and variables explicitly initialized to 0, are placed in the .bss section of memory.

This section is initialized to 0 by the CRT (C Runtime) code (the startup code for the system).

The compiler is responsible for placing these variables in the .bss, but it is the job of the startup (CRT) code to initialize it to zero.

This is standard C operation and is not likely to ever change since it would break all sorts of things.

I'm used to this way from my desktop C++ programming practice:

int array[100] = {0};

I couldn't find any info on whether or not this construct works on Arduino.

The = {0} has no actual effect. It is the same as:

int array[100];

Uninitialized static / global variables, and variables explicitly initialized to 0, are placed in the .bss section of memory.

This section is initialized to 0 by the CRT (C Runtime) code (the startup code for the system).

The compiler is responsible for placing these variables in the .bss, but it is the job of the startup (CRT) code to initialize it to zero.

This is standard C operation and is not likely to ever change since it would break all sorts of things.

Note: this does NOT apply to local variables allocated on the stack. These must be initialized to 0 if you want them to start as 0.

Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

I'm used to this way from my desktop C++ programming practice:

int array[100] = {0};

I couldn't find any info on whether or not this construct works on Arduino.

The = {0} has no actual effect. It is the same as:

int array[100];

Uninitialized static / global variables, and variables explicitly initialized to 0, are placed in the .bss section of memory.

This section is initialized to 0 by the CRT (C Runtime) code (the startup code for the system).

The compiler is responsible for placing these variables in the .bss, but it is the job of the startup (CRT) code to initialize it to zero.

This is standard C operation and is not likely to ever change since it would break all sorts of things.