Skip to content

Commit 63721ac

Browse files
docs: int is platform width, not always 32-bit
Since #28293 (25f5ced) `int` lowers to `i64` on 64-bit targets and to `i32` on 32-bit ones, but the Primitive types note still said "Unlike C and Go, `int` is always a 32 bit integer". The raw inline-assembly example had the same stale assumption: it used `addl` on two `int` operands, which fails under gcc with "incorrect register `%rax' used with `l' suffix" (the same problem as #28870). Its operands are now `i32`, with a sentence on why. Co-Authored-By: WOZCODE <contact@withwoz.com>
1 parent c9b806b commit 63721ac

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎doc/docs.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ voidptr // this one is mostly used for [C interoperability](#v-and-c)
631631
```
632632

633633
> [!NOTE]
634-
> Unlike C and Go, `int` is always a 32 bit integer.
634+
> `int` is a platform-width signed integer: 64 bits on 64-bit targets and 32 bits on 32-bit
635+
> targets. Use `i32` or `i64` when you need a fixed width.
635636
636637
There is an exception to the rule that all operators
637638
in V must have values of the same type on both sides. A small primitive type
@@ -9314,8 +9315,8 @@ double-quoted template string through unchanged and still checks the output, inp
93149315
lists. Operands can use GNU's named form or V's `constraint (expression) as alias` form:
93159316
93169317
```v ignore
9317-
mut value := 40
9318-
increment := 2
9318+
mut value := i32(40)
9319+
increment := i32(2)
93199320
asm amd64 raw {
93209321
"addl %[increment], %[value]\n\t"
93219322
; [value] "+r" (value)
@@ -9325,6 +9326,10 @@ asm amd64 raw {
93259326
assert value == 42
93269327
```
93279328
9329+
The operands are `i32` because `addl` is a 32-bit instruction: a plain `int` is 64 bits wide on a
9330+
64-bit target, so the C compiler would substitute a 64-bit register, which the GNU assembler
9331+
rejects for an `l`-suffixed instruction.
9332+
93289333
Raw templates are the right level for hand-written kernels that need GNU assembler features such
93299334
as local labels or explicit operand modifiers. A label made with `%=` gets a unique numeric suffix
93309335
for each inline-assembly statement, so prefer names such as `.Lloop%=` for loops in reusable

0 commit comments

Comments
 (0)