Literal expression

From MSX Game Library

Revision as of 22:25, 13 January 2024 by Aoineko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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