From: Stefan Hellermann <stefan@the2masters.de>
To: caml-list@inria.fr
Subject: [Caml-list] [PATCH 1/2] configure: Check sizes of integers and pointers by using the preprocessor
Date: Fri, 9 Oct 2015 14:03:13 +0200 [thread overview]
Message-ID: <1444392194-18276-2-git-send-email-stefan@the2masters.de> (raw)
In-Reply-To: <1444392194-18276-1-git-send-email-stefan@the2masters.de>
Signed-off-by: Stefan Hellermann <stefan@the2masters.de>
---
config/auto-aux/preprocesstest | 22 +++++++++++
config/auto-aux/sizes.c | 85 ++++++++++++++++++++++++++++++------------
configure | 2 +-
3 files changed, 85 insertions(+), 24 deletions(-)
create mode 100755 config/auto-aux/preprocesstest
diff --git a/config/auto-aux/preprocesstest b/config/auto-aux/preprocesstest
new file mode 100755
index 0000000..9c66047
--- /dev/null
+++ b/config/auto-aux/preprocesstest
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+#########################################################################
+# #
+# OCaml #
+# #
+# Xavier Leroy, projet Cristal, INRIA Rocquencourt #
+# #
+# Copyright 1995 Institut National de Recherche en Informatique et #
+# en Automatique. All rights reserved. This file is distributed #
+# under the terms of the GNU Library General Public License, with #
+# the special exception on linking described in file ../../LICENSE. #
+# #
+#########################################################################
+
+if test "$verbose" = yes; then
+echo "preprocesstest: $cc -o tst $* $cclibs" >&2
+$cc -E -P -o tst $* $cclibs || exit 100
+else
+$cc -E -P -o tst $* $cclibs 2> /dev/null || exit 100
+fi
+tail -n 1 ./tst
diff --git a/config/auto-aux/sizes.c b/config/auto-aux/sizes.c
index d756952..5290b93 100644
--- a/config/auto-aux/sizes.c
+++ b/config/auto-aux/sizes.c
@@ -1,25 +1,64 @@
-/***********************************************************************/
-/* */
-/* OCaml */
-/* */
-/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
-/* */
-/* Copyright 1996 Institut National de Recherche en Informatique et */
-/* en Automatique. All rights reserved. This file is distributed */
-/* under the terms of the GNU Library General Public License, with */
-/* the special exception on linking described in file ../../LICENSE. */
-/* */
-/***********************************************************************/
+#include <limits.h>
+#include <stdint.h>
-#include <stdio.h>
+#if UINT_MAX == 255ULL
+#define SIZEOFINT 1
+#elif UINT_MAX == 65535ULL
+#define SIZEOFINT 2
+#elif UINT_MAX == 4294967295ULL
+#define SIZEOFINT 4
+#elif UINT_MAX == 18446744073709551615ULL
+#define SIZEOFINT 8
+#else
+#error Cannot evaluate sizeof(int)
+#endif
-int main(int argc, char **argv)
-{
- printf("%d %d %d %d %d\n",
- (int) sizeof(int),
- (int) sizeof(long),
- (int) sizeof(long *),
- (int) sizeof(short),
- (int) sizeof(long long));
- return 0;
-}
+#if ULONG_MAX == 255ULL
+#define SIZEOFLONG 1
+#elif ULONG_MAX == 65535ULL
+#define SIZEOFLONG 2
+#elif ULONG_MAX == 4294967295ULL
+#define SIZEOFLONG 4
+#elif ULONG_MAX == 18446744073709551615ULL
+#define SIZEOFLONG 8
+#else
+#error Cannot evaluate sizeof(long)
+#endif
+
+#if SIZE_MAX == 255ULL
+#define SIZEOFPOINTER 1
+#elif SIZE_MAX == 65535ULL
+#define SIZEOFPOINTER 2
+#elif SIZE_MAX == 4294967295ULL
+#define SIZEOFPOINTER 4
+#elif SIZE_MAX == 18446744073709551615ULL
+#define SIZEOFPOINTER 8
+#else
+#error Cannot evaluate sizeof(*ptr)
+#endif
+
+#if USHRT_MAX == 255ULL
+#define SIZEOFSHORT 1
+#elif USHRT_MAX == 65535ULL
+#define SIZEOFSHORT 2
+#elif USHRT_MAX == 4294967295ULL
+#define SIZEOFSHORT 4
+#elif USHRT_MAX == 18446744073709551615ULL
+#define SIZEOFSHORT 8
+#else
+#error Cannot evaluate sizeof(short)
+#endif
+
+#if ULLONG_MAX == 255ULL
+#define SIZEOFLONGLONG 1
+#elif ULLONG_MAX == 65535ULL
+#define SIZEOFLONGLONG 2
+#elif ULLONG_MAX == 4294967295ULL
+#define SIZEOFLONGLONG 4
+#elif ULLONG_MAX == 18446744073709551615ULL
+#define SIZEOFLONGLONG 8
+#else
+#error Cannot evaluate sizeof(long long)
+#endif
+
+SIZEOFINT SIZEOFLONG SIZEOFPOINTER SIZEOFSHORT SIZEOFLONGLONG
diff --git a/configure b/configure
index 5596523..e3ea7eb 100755
--- a/configure
+++ b/configure
@@ -495,7 +495,7 @@ fi # cross-compiler
# a 64-bit integer type
inf "Checking the sizes of integers and pointers..."
-ret=`sh ./runtest sizes.c`
+ret=`sh ./preprocesstest sizes.c`
# $1 = sizeof(int)
# $2 = sizeof(long)
# $3 = sizeof(pointers)
--
2.1.4
next prev parent reply other threads:[~2015-10-09 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-09 12:03 [Caml-list] [PATCH 0/2] use preprocessor to get infos about target arch Stefan Hellermann
2015-10-09 12:03 ` Stefan Hellermann [this message]
2015-10-09 12:03 ` [Caml-list] [PATCH 2/2] configure: Check endianess by using the preprocessor Stefan Hellermann
2015-10-09 12:24 ` [Caml-list] [PATCH 0/2] use preprocessor to get infos about target arch Daniel Bünzli
2015-10-09 12:31 ` Stefan Hellermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444392194-18276-2-git-send-email-stefan@the2masters.de \
--to=stefan@the2masters.de \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox