The GNU cross compilers for Arduino use C/C++ front-ends and meet the language specs. You can expect fully compliant output. "Arduino language" is a misnomer. The Arduino IDE will try to assist new programmers by, for example, automagically discovering library references and inserting the required #includes for you, but the resulting code is C++ and presented to a C++ compiler. The IDE provides a main()
function that calls setup()
and loop()
(and serialEventRun()
if you provide one) thereby reminding the programmer to initialize whatever needs to be initialized before expecting things to work right. However you can write proper C++ and get what you've come to expect. You'd have to go 'behind the IDE's back' as it were to suppress the auto-supplied main()
function, but the toolchain doesn't care how that part was done, as long as there is one.
I tested this this trivial program:
int array[100];
void setup() {
// put your setup code here, to run once:
for(uint8_t i = 0; i < sizeof(array); ++i)
array[i] = i;
}
void loop() {
// put your main code here, to run repeatedly:
}
with both the Arduino IDE and Sloeber - Eclipse with the EclipseArduino plugin, which routinely provides a basic memory map after compilation - and with and without the initialization expression = {0}
. I found no difference in the size of the output in either environment, with or without the initialization. In all four cases, the .bss was 209 bytes, 200 bytes larger than without the global array.
= {0}
that without it, so the compiler is definitely doing something. On the other hand, in my test the array was all0
s both with and without= {0}
. Problem is, that proves nothing. It doesn't guarantee that it will work on some other compiler with some other settings. The testing would only be conclusive if it demonstrated that this code does not work.= {0}
does nothing by the way) but the CRT (initialization code). Maybe this will explain: en.wikipedia.org/wiki/.bss