From 055d842c1205af1be78b68b7b3124e8de49b2076 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Sun, 3 Nov 2019 23:33:58 +0100 Subject: [PATCH] Document inferred literal types --- docs/lang/literals.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/lang/literals.md b/docs/lang/literals.md index f9eeb91f..3ae46e72 100644 --- a/docs/lang/literals.md +++ b/docs/lang/literals.md @@ -17,6 +17,14 @@ Hexadecimal: `$D323`, `0x2a2` When using Intel syntax for inline assembly, another hexadecimal syntax is available: `0D323H`, `2a2h`. It is not allowed in any other places. +The type of a literal is the smallest type of undefined signedness +that can fit either the unsigned or signed representation of the value: +`200` is a `byte`, `4000` is a `word`, `75000` is an `int24` etc. + +However, padding the literal to the left with zeroes changes the type +to the smallest type that can fit the smallest number with the same number of digits and without padding. +For example, `0002` is of type `word`, as 1000 does not fit in one byte. + ## String literals String literals can be used as either array initializers or expressions of type `pointer`.