From 9dbe6d3478329df159cf402c1812485649741e7c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 20 Dec 2015 15:54:26 +0100 Subject: It is of course possible that int is 16 bits, and long is required to get 32 bits (in this case, assuming 8-, 16-, and 32-bit integers exists) long must be 32 bits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- gen/bits/intconf.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'gen/bits/intconf.c') diff --git a/gen/bits/intconf.c b/gen/bits/intconf.c index 361dd16..4fe45fd 100644 --- a/gen/bits/intconf.c +++ b/gen/bits/intconf.c @@ -173,17 +173,34 @@ static char* byteorder_16(void) static char* byteorder_32(void) { static char buf[32 / 4 + 1]; - union - { - int all; - struct + if (8 * sizeof(int) == 32) { - char a; char b; char c; char d; - }; - } test = { .all = 0x01020304 }; + union + { + int all; + struct + { + char a; char b; char c; char d; + }; + } test = { .all = 0x01020304 }; - sprintf(buf, "%02i%02i%02i%02i", - test.a, test.b, test.c, test.d); + sprintf(buf, "%02i%02i%02i%02i", + test.a, test.b, test.c, test.d); + } + else + { + union + { + long int all; + struct + { + char a; char b; char c; char d; + }; + } test = { .all = 0x01020304L }; + + sprintf(buf, "%02i%02i%02i%02i", + test.a, test.b, test.c, test.d); + } return buf; } @@ -245,7 +262,7 @@ int main(int argc, char* argv[]) /* Print byte orders. */ r |= printf("INT16_BYTEORDER 0x%s\n", byteorder_16()); - r |= printf("INT32_BYTEORDER 0x%s\n", byteorder_32()); + r |= printf("INT32_BYTEORDER 0x%sL\n", byteorder_32()); r |= printf("INT64_BYTEORDER 0x%sLL\n", byteorder_64()); /* Print the intrinsic type for specific numbers of bits. */ -- cgit v1.2.3-70-g09d2