Skip to content

Commit 496b8b2

Browse files
committed
Compare INT_MAX instead of sizeof(int)
davidben has pointed out that signed integers can have padding so it's possible their sizeof() is > 4 even though their max value still fits in 4 bytes. Truncating back down to an int32 (ot uint32) would be fine in that case.
1 parent 7237470 commit 496b8b2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

subspace/lib/lib.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
// Architectural assumptions we make throughout the implementation of Subspace.
2222
static_assert(CHAR_BIT == 8);
23-
static_assert(sus::mem::size_of<int>() == 4);
23+
// Signed integers are allowed to have padding so they can have a larger size
24+
// thus we don't compare the size of `int` but its max value instead.
25+
static_assert(INT_MAX == INT32_MAX);
2426
static_assert(sus::mem::size_of<size_t>() >= 4);
2527
static_assert(sus::mem::size_of<size_t>() <= 8);
2628

0 commit comments

Comments
 (0)