Skip to content

Fix 32-bit build

Michael Catanzaro requested to merge mcatanzaro/#357 into master
Fix 32-bit build

Problem is that each separate 'if constexpr' block needs to evaluate to
the same return type. The first block returns GType (long unsigned int).
On x86_64, the second block returns uint64_t (long unsigned int), and
everything is fine. But on i686, the second block instead returns
uint32_t (unsigned int). The types are different, and the build fails.
It doesn't matter that long unsigned int and unsigned int are the same
size on i686: they are different types, so it fails anyway.

I learned a few things about types when working on this. Vanilla int and
unsigned int are always 32 bits on Linux (not surprising), and long long
int and unsigned long long int are always 64 bits (also not surprising).
But I had never previously learned the rule for long int and unsigned
long int. Turns out it matches word size, so long is 64 bits on x86_64
but 32 bits on i686. That's interesting.

I also learned that GType is always long unsigned int in C++. In C, it
is long unsigned int on 64-bit architectures, but it is gsize (size_t)
on 32-bit architectures. That's right, on 32-bit systems, the size of
GType differs based on what programming language you use! I guess if
there are no explosions in practice, and nobody registers more than
four billion types per process, it must be OK?

Thanks to Abderrahim for preparing an earlier version of this fix, and
to both Abderrahim and Jordan for helping me with BuildStream to do an
i686 build.

Fixes #357
Edited by Michael Catanzaro

Merge request reports