incorrect type signedness for limits.h replacement, unchecked sizes not guaranteeing portability by standard #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
problem source: "wchar_t is unsigned or signed" https://stackoverflow.com/a/11953419
"The signedness of wchar_t is unspecified. The standard only says (3.9.1/5):"
C standard further does not guarantee sizes, which you typedef. So they should be checked with macros/compiler.
From playing with the idea to write a test framework, I got the following macros to check sizes and signedness.
Unfortunately you do not write compatibility of the C standard (C11 mandates _Static_assert), so you might need to adapt them further.
For example,
typedef unsigned short wchar16_t;is wrong and the user must specify it, if is necessary and for portability must _Static_assert it.The best you can do is to provide example files, so from my point of view this should also be BSD0 licensed to make clear that stuff must be potentially modified etc.
If you have a complete list of architectures or would accept all possible architectures, that would look different. ;)
One solution to this is:
If you think otherwise, please add the Assumptions (unchecked things) and Assertions (checked things) to README.md.
Let me know, what you think.
One can autogenerate those definitions with grepping for
__SIZEOF_INT__and co as explained herehttps://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
__has_include("limits.h")
__has_include("stdint.h")
to autogenerate the static assertions for checking
if code assumptions also hold on the other platforms.
Without limits and stdint all bets are off.
This also works for signedness of char, ie with
https://exchangetuts.com/what-causes-a-char-to-be-signed-or-unsigned-when-using-gcc-1639592646188352
see also
https://github.com/ziglang/zig/pull/11447