user39661: I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int occupies less than an int).
If instead of int I use const uint8_t, const uint16_t etc. is the optimization still applied, or does using the 8 and 16 bit ints represent bad practice?

user31105: Const memory will still store ts value both in Flash and in SRAM. For arrays PROGMEM can be used and for strings F() to remove the copy to SRAM.
Normal (non const) memory will be stored in SRAM. And if it is initialized with a value, that value is stored in Flash.
However, uint8_t will always occupy 1 byte, and uint16_t always two bytes.
You can read more about the different types of memory and F here.
You can read more about program here.
Update:
Test with const:
const uint8_t  Amount1 = 4;
const uint8_t  Amount2 = 4;
const uint8_t  Amount3 = 4;
const uint8_t  Amount4 = 4;
const uint8_t  Amount5 = 4;
const uint8_t  Amount6 = 4;
const uint8_t  Amount7 = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print(Amount1);
  Serial.print(Amount2);
  Serial.print(Amount3);
  Serial.print(Amount4);
  Serial.print(Amount5);
  Serial.print(Amount6);
  Serial.print(Amount7);
}

Result: 1758 bytes of program storage space, 184 bytes of dynamic memory.
Same without word 'const:
Result: 1758 bytes of program storage space, 184 bytes of dynamic memory.
No difference
using #define Amount1..7 4
Result: 1702 bytes of program storage space, 184 bytes of dynamic memory.
Conclusion: to save Flash space, use #define instead of (const) uint8_t.
However, also see Jot's experiment, it seems that code optimalization is smarter than my conclusion.

user13432: This question is not really about the Arduino. It is about GNU C/C++ compiler optimizations. 
By adding the keyword const the compiler can do a lot of optimization. One is that the value does not need to be stored in SRAM. The value can end up as part of an instruction, become part of an expression that is evaluated at compile-time, etc. 
In the Arduino-GPIO library static const member data is used to allow the compiler to optimize to a single instruction digitalRead() with almost X100 performance improvement (on Arduino Mega). 
Check GCC and AVR optimizations for further details. 

http://www.nongnu.org/avr-libc/user-manual/using_tools.html
https://gcc.gnu.org/wiki/avr-gcc
http://www.linuxjournal.com/article/7269

Cheers!

39661: <p>I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int occupies less than an int).</p>

<p>If instead of int I use const uint8_t, const uint16_t etc. is the optimization still applied, or does using the 8 and 16 bit ints represent bad practice?</p>
 31105: <p>Const memory will still store ts value both in Flash and in SRAM. For arrays PROGMEM can be used and for strings F() to remove the copy to SRAM.</p>

<p>Normal (non const) memory will be stored in SRAM. And if it is initialized with a value, that value is stored in Flash.</p>

<p>However, uint8_t will always occupy 1 byte, and uint16_t always two bytes.</p>

<p>You can read more about the different types of memory and F <a href="http://playground.arduino.cc/Learning/Memory" rel="nofollow noreferrer">here</a>.</p>

<p>You can read more about program <a href="https://www.arduino.cc/reference/en/language/variables/utilities/progmem/" rel="nofollow noreferrer">here</a>.</p>

<p>Update:</p>

<p>Test with const:</p>

<pre><code>const uint8_t  Amount1 = 4;
const uint8_t  Amount2 = 4;
const uint8_t  Amount3 = 4;
const uint8_t  Amount4 = 4;
const uint8_t  Amount5 = 4;
const uint8_t  Amount6 = 4;
const uint8_t  Amount7 = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print(Amount1);
  Serial.print(Amount2);
  Serial.print(Amount3);
  Serial.print(Amount4);
  Serial.print(Amount5);
  Serial.print(Amount6);
  Serial.print(Amount7);
}
</code></pre>

<p>Result: 1758 bytes of program storage space, 184 bytes of dynamic memory.</p>

<p>Same without word 'const:</p>

<p>Result: 1758 bytes of program storage space, 184 bytes of dynamic memory.
No difference</p>

<p>using #define Amount1..7 4</p>

<p>Result: 1702 bytes of program storage space, 184 bytes of dynamic memory.</p>

<p>Conclusion: to save Flash space, use #define instead of (const) uint8_t.
However, also see Jot's experiment, it seems that code optimalization is smarter than my conclusion.</p>
 13432: <p>This question is not really about the Arduino. It is about GNU C/C++ compiler optimizations. </p>

<p>By adding the keyword <code>const</code> the compiler can do a lot of optimization. One is that the value does not need to be stored in SRAM. The value can end up as part of an instruction, become part of an expression that is evaluated at compile-time, etc. </p>

<p>In the <a href="https://github.com/mikaelpatel/Arduino-GPIO/blob/master/src/Hardware/AVR/GPIO.h" rel="nofollow noreferrer">Arduino-GPIO</a> library <code>static const</code> member data is used to allow the compiler to optimize to a single instruction <code>digitalRead()</code> with almost X100 performance improvement (on Arduino Mega). </p>

<p>Check GCC and AVR optimizations for further details. </p>

<ol>
<li><a href="http://www.nongnu.org/avr-libc/user-manual/using_tools.html" rel="nofollow noreferrer">http://www.nongnu.org/avr-libc/user-manual/using_tools.html</a></li>
<li><a href="https://gcc.gnu.org/wiki/avr-gcc" rel="nofollow noreferrer">https://gcc.gnu.org/wiki/avr-gcc</a></li>
<li><a href="http://www.linuxjournal.com/article/7269" rel="nofollow noreferrer">http://www.linuxjournal.com/article/7269</a></li>
</ol>

<p>Cheers!</p>
