From 6297d437585be15616a47802c84f592447ed5cdd Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 30 Apr 2012 22:22:05 +0200 Subject: changed size to a bigint --- tests/Makefile | 7 +++++++ tests/testtypes.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/testtypes.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 3d09117..a092b40 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -60,6 +60,7 @@ test: testfsync testpgsql clean: rm -f testfsync testfsync.o rm -f testpgsql testpgsql.o + rm -f testtypes testtypes.o testfsync: testfsync.o $(CC) -o testfsync testfsync.o @@ -72,3 +73,9 @@ testpgsql: testpgsql.o testpgsql.o: testpgsql.c $(CC) -c $(CFLAGS) -o testpgsql.o testpgsql.c + +testtypes: testtypes.o + $(CC) -o testtypes testtypes.o + +testtypes.o: testtypes.c + $(CC) -c $(CFLAGS) -o testtypes.o testtypes.c diff --git a/tests/testtypes.c b/tests/testtypes.c new file mode 100644 index 0000000..339af5d --- /dev/null +++ b/tests/testtypes.c @@ -0,0 +1,32 @@ +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include /* for time_t */ +#include /* for off_t */ + +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) +#define TYPE_MAX(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + +int main(void) +{ + uint32_t uint32=0xffffFFFF; + uint64_t uint64=0xFFFFFFFFFFFFFFFF; + off_t offset=TYPE_MAX(off_t); /* Depends on _FILE_OFFSET_BITS */ + size_t size=TYPE_MAX(size_t); /* Depends on int size */ + + printf("native int bits%20u %16x\n", sizeof(int)*CHAR_BIT, UINT_MAX); + printf("uint32_t max %20"PRIu32" %16"PRIx32"\n" + "uint64_t max %20"PRIu64" %16"PRIx64"\n" + "off_t max %20jd %16jx\n" /* try PRIdMAX if %jd unsupported */ + "size_t max %20zu %16zx\n", + uint32, uint32, + uint64, uint64, + (intmax_t)offset, (intmax_t)offset, + size, size); + + return 0; +} -- cgit v1.2.3-54-g00ecf