-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Detect platform word size based on SIZE_MAX
#125
fix: Detect platform word size based on SIZE_MAX
#125
Conversation
The native word size on a platform matches the size of `size_t` with a few rare exceptions like the x32 ABI on linux. Therefore we can derive a general cross platform value for `BASE64_WORDSIZE` based on `SIZE_MAX` which the C99 standard guarantees to be available and well defined. This fixes the misdection of x86/arm32 win32 as a 64bit platform. See also https://en.cppreference.com/w/c/types/limits
09dc6b6
to
e826739
Compare
#elif defined (__WORDSIZE) | ||
# define BASE64_WORDSIZE __WORDSIZE | ||
#elif defined (__SIZE_WIDTH__) | ||
# define BASE64_WORDSIZE __SIZE_WIDTH__ | ||
#elif SIZE_MAX == 0xffffffff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#elif SIZE_MAX == 0xffffffff | |
#elif SIZE_MAX == UINT32_MAX |
#elif defined (__WORDSIZE) | ||
# define BASE64_WORDSIZE __WORDSIZE | ||
#elif defined (__SIZE_WIDTH__) | ||
# define BASE64_WORDSIZE __SIZE_WIDTH__ | ||
#elif SIZE_MAX == 0xffffffff | ||
# define BASE64_WORDSIZE 32 | ||
#elif SIZE_MAX == 0xffffffffffffffff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#elif SIZE_MAX == 0xffffffffffffffff | |
#elif SIZE_MAX == UINT64_MAX |
@BurningEnlightenment, I did not write anything related to |
Merged with the fixes proposed by @mayeut. @BurningEnlightenment I slightly modified the commit title to add the issue number, and I modified the commit body to mark this issue and #123 as resolved. Hope you don't mind. |
@BurningEnlightenment I think it's a bit too late now to force-push to the master branch, so yes, please open a new PR. |
The native word size on a platform matches the size of
size_t
with a few rare exceptions like the x32 ABI on linux. Therefore we can derive a general cross platform value forBASE64_WORDSIZE
based onSIZE_MAX
which the C99 standard guarantees to be available and well defined.This fixes the misdection of x86/arm32 win32 as a 64bit platform, i.e. it is an alternative to #123
@mayeut I think this should also cover the
__WORDSIZE
and__SIZE_WIDTH__
cases. Can you verify this? If that indeed is the case I would like remove those branches, too.See also https://en.cppreference.com/w/c/types/limits