Difference between revisions of "Literal expression"

From MSX Game Library

(Created page with "{{MSXGL}} is using sdcc11 option for compile C code that is described as « ''Generally follow the [https://en.wikipedia.org/wiki/C11_(C_standard_revision) ISO C11 standard],...")
 
Line 1: Line 1:
 
{{MSXGL}} is using sdcc11 option for compile C code that is described as « ''Generally follow the [https://en.wikipedia.org/wiki/C11_(C_standard_revision) ISO C11 standard], but allow some SDCC behaviour that conflicts with the standard'' ».
 
{{MSXGL}} is using sdcc11 option for compile C code that is described as « ''Generally follow the [https://en.wikipedia.org/wiki/C11_(C_standard_revision) ISO C11 standard], but allow some SDCC behaviour that conflicts with the standard'' ».
 +
 +
For literal expressions, the C11 standard applies.
 +
These expressions are interpreted during the preprocessing phase and are replaced by their final value for compilation.
 +
 +
For example:
 +
u8 a = (10 * 5) - 12; // 38
 +
i16 b = 8 * 1024 / 3; // 2730
 +
i8 c = 3.141593 * -10; // -31 (generate warning)
 +
 +
To help the preprocessor to determine the type of numbers you can either:
 +
* Cast the number or/and the result to the type of your choice,
 +
u8 d = (u8)(255-1);
 +
i16 e = (i16)(66000/3);
 +
* Use C11 postfix U, L or LL.
 +
U: Unsigned integer
 +
L: 32-bits integer
 +
LL: 64-bits integer

Revision as of 12:35, 5 June 2022

MSXGL is using sdcc11 option for compile C code that is described as « Generally follow the ISO C11 standard, but allow some SDCC behaviour that conflicts with the standard ».

For literal expressions, the C11 standard applies. These expressions are interpreted during the preprocessing phase and are replaced by their final value for compilation.

For example:

u8 a = (10 * 5) - 12; // 38
i16 b = 8 * 1024 / 3; // 2730
i8 c = 3.141593 * -10; // -31 (generate warning)

To help the preprocessor to determine the type of numbers you can either:

  • Cast the number or/and the result to the type of your choice,
u8 d = (u8)(255-1);
i16 e = (i16)(66000/3);
  • Use C11 postfix U, L or LL.
U: Unsigned integer
L: 32-bits integer
LL: 64-bits integer