Post #1287409
2026-04-09 13:36 UTC
How is there no standard MiB constant of 1024*1024 in the C standard? What do other codebases do?
Replies (5)
-
@leo@60228.dev 2026-04-09 13:37
@hughsie 1024*1024 is the same length any constant would likely be and not really any less clear imo
-
@23n27@dgc.social 2026-04-09 13:49
@hughsie LZ4 is doing this, which is both neat and a bit creepy: https://github.com/lz4/lz4/blob/9da37b2eebf082bfab6e57c49be71cc41119a40d/programs/bench.c#L74C9-L80
-
@pauldoo@mastodon.scot 2026-04-09 14:07
@hughsie My go-to is `1 << 10`, `1 << 20`, `1 << 30`, and `1 << 40` for KiB, MiB, GiB, and TiB respectively.
-
@andyprice@mastodon.social 2026-04-09 14:21
@hughsie I'm not sure I see the value (heh) in it as part of the C standard.
-
@karolherbst@chaos.social 2026-04-09 16:01
@hughsie #include #define MB << 20 int main() { printf("0x%x\n", 5 MB); }