# Why u32/i32 and not u32/s32?

**URL:** <https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441>\
**Category:** Explain\
**Tags:** language\
**Created:** [May 25, 2024, 2:22pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441 "2024-05-25T14:22:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [May 25, 2024, 2:22pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/1 "2024-05-25T14:22:32Z")

</div>

In `u32/s32` `u` means “ **u** nsigned (integer implied)” and `s` means “ **s** igned (integer implied)”, these are antonyms and this is ok. In `u32/i32` `u`, again, means “unsigned (integer)” and `i` means just “integer”, which is a bit inhomogeneous, it’s about different things.

Of course, I can always redefine this with `const s32 = i32;`, but, anyway, why `i32` but not `s32`? After Rust? 🙂

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [May 25, 2024, 2:31pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/2 "2024-05-25T14:31:43Z")

</div>

Integer in math can be positive or negative, that justifies the i prefix. Also Natural Number is a better name for positive numbers. n32/i32 is the best 🙂  
I believe that `i` comes from C `int` and `u` comes from C `unsigned`.

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [May 25, 2024, 2:43pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/3 "2024-05-25T14:43:03Z")

</div>

> [@dimdin](#):
>
> Integer in math can be positive or negative, that justifies the i prefix

Yes, but integers in a _computer_ may be signed or unsigned (and it is very important for a programmer, but not for a mathematician), that justifies `u32/s32`. 🙂 It’s not my “invention”, as you guessed… Linux kernel uses such typedefs.

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [May 25, 2024, 3:37pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/4 "2024-05-25T15:37:59Z")

</div>

```zig
// redef-i32.zig
pub const s32 = i32;

```

```zig
// s32.zig
const std = @import("std");
const int = @import("redef-i32.zig");

pub fn main() void {
    const n: int.s32 = -7;
    std.debug.print("n = {}\n", .{n});
}

```

🙂

`int.s32` looks pretty well - “integer”, “signed”, “32 bits wide”.

---

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [May 25, 2024, 5:31pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/6 "2024-05-25T17:31:41Z")

</div>

… or even like this, kinda joke:

```zig
// integer-types.zig
pub const @"без-знака" = struct {
    pub const @"16-бит" = u16;
    pub const @"32-бит" = u32;
};

pub const @"со-знаком" = struct {
    pub const @"16-бит" = i16;
    pub const @"32-бит" = i32;
};

```

and then

```zig
// s32-b.zig
const std = @import("std");
const @"целое" = @import("integer-types.zig");

pub fn main() void {
    const n: @"целое".@"со-знаком".@"32-бит" = -7;
    std.debug.print("n = {}\n", .{n});
}

```

LOL. 🤣

- “целое” - “integer”
- “без знака” - “unsigned”
- “со знаком” - “signed”

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [June 1, 2024, 9:28pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/7 "2024-06-01T21:28:31Z")

</div>

10 posts were split to a new topic: [On Vector Syntax](https://ziggit.dev/t/on-vector-syntax/4530)

---

<div class="post-metadata">

**Author:** ![pachde](https://ziggit.dev/user_avatar/ziggit.dev/pachde/32/2485_2.png) [@pachde](https://ziggit.dev/u/pachde)\
**Post date:** [June 5, 2024, 1:00am UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/8 "2024-06-05T01:00:02Z")

</div>

I can’t tell you how many codebases I’ve read that use `s`… for ‘string’.

---

<div class="post-metadata">

**Author:** ![marler8997](https://ziggit.dev/user_avatar/ziggit.dev/marler8997/32/77_2.png) [@marler8997](https://ziggit.dev/u/marler8997)\
**Post date:** [June 7, 2024, 11:05pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/9 "2024-06-07T23:05:48Z")

</div>

I don’t know if this is the real answer but it could be based on C, `int` vs `unsigned`.

---

<div class="post-metadata">

**Author:** ![nyc](https://ziggit.dev/user_avatar/ziggit.dev/nyc/32/1167_2.png) [@nyc](https://ziggit.dev/u/nyc)\
**Post date:** [June 7, 2024, 11:59pm UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/10 "2024-06-07T23:59:09Z")

</div>

I assume it is because that is what LLVM uses (which is probably based on C like you said).

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [June 8, 2024, 12:34am UTC](https://ziggit.dev/t/why-u32-i32-and-not-u32-s32/4441/11 "2024-06-08T00:34:58Z")

</div>

Linux picked the less usual convention, but the whole `u16` / `u32` / `i16` etc. thing has a really old history in C. If you needed integer types of a defined width, you used to have to do some platform specific macro trickery to get them in a portable way.

That’s why the later standard went with the more verbose `uint8_t` thing actually, so it wouldn’t interfere with the shorter versions which were already in heavy use in existing code.

So yeah, that’s why LLVM is like that as well.
