summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-10-30 09:05:06 -0700
committerAdrian Thurston <thurston@colm.net>2021-11-06 12:06:28 -0700
commite1f1c598d5bf66484e4dccccddd420a8ed1ebc84 (patch)
tree7c79e63f3e309a975e567686bbab49d1dad8a901
parent3a818005b5255ab00950623b01698ab1ef55aab5 (diff)
downloadcolm-e1f1c598d5bf66484e4dccccddd420a8ed1ebc84.tar.gz
C codegen: decide char signedness based on value of CHAR_MIN
Decide signedness of "char" on at runtime (probably compile time) using a check on CHAR_MIN. This should work with cross compiling setups. With this approach, if you plan to use "char" on ARM you cannot literally specify outside the range 0-127 using decimal/hex. If you need that you can use "signed char" or "unsigned char".
-rw-r--r--src/libfsm/common.cc24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libfsm/common.cc b/src/libfsm/common.cc
index 9ebbd905..b46cc571 100644
--- a/src/libfsm/common.cc
+++ b/src/libfsm/common.cc
@@ -41,18 +41,18 @@ const char *defaultOutFnC( const char *inputFileName )
HostType hostTypesC[] =
{
- { "char", 0, "char", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, sizeof(char) },
- { "signed", "char", "char", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, sizeof(char) },
- { "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) },
- { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(short) },
- { "signed", "short", "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(short) },
- { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
- { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
- { "signed", "int", "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
- { "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) },
- { "long", 0, "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(long) },
- { "signed", "long", "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(long) },
- { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
+ { "char", 0, "char", (CHAR_MIN != 0), true, false, SCHAR_MIN, SCHAR_MAX, 0, UCHAR_MAX, sizeof(char) },
+ { "signed", "char", "char", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, sizeof(char) },
+ { "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) },
+ { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(short) },
+ { "signed", "short", "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(short) },
+ { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
+ { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
+ { "signed", "int", "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
+ { "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) },
+ { "long", 0, "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(long) },
+ { "signed", "long", "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(long) },
+ { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
};
const HostLang hostLangC = {