Skip to main content
Add note re: recent IDEs meeting recent language specs.
Source Link
JRobert
  • 15.4k
  • 3
  • 25
  • 53

The GNU cross compilers for Arduino use C/C++ front-ends and meet some version the language specs. You(Although that is a moving target, you can expect fullya recent IDE version will be compliant outputwith a reasonably recent language spec.)

"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 will be 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 autoautomatically-supplied main() function, but the toolchain doesn't care how that part was done, as long as there is one and only one, main().

I tested this this trivial program:

int array[100];

    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.

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.

The GNU cross compilers for Arduino use C/C++ front-ends and meet some version the language specs. (Although that is a moving target, you can expect a recent IDE version will be compliant with a reasonably recent language spec.)

"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 will be 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 automatically-supplied main() function, but the toolchain doesn't care, as long as there is one and only one, main().

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.

added 5 characters in body
Source Link
JRobert
  • 15.4k
  • 3
  • 25
  • 53

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. ItThe 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.

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. It 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.

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.

Source Link
JRobert
  • 15.4k
  • 3
  • 25
  • 53

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. It 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.