Literal expression

From MSX Game Library

Revision as of 12:35, 5 June 2022 by Aoineko (talk | contribs)

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