diff options
Diffstat (limited to 'mcon/U/charsize.U')
-rw-r--r-- | mcon/U/charsize.U | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/mcon/U/charsize.U b/mcon/U/charsize.U index 388e5c1..7135e5b 100644 --- a/mcon/U/charsize.U +++ b/mcon/U/charsize.U @@ -1,11 +1,11 @@ -?RCS: $Id: charsize.U 1 2006-08-24 12:32:52Z rmanfredi $ +?RCS: $Id: charsize.U 167 2013-05-08 17:58:00Z rmanfredi $ ?RCS: ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi ?RCS: -?RCS: You may redistribute only under the terms of the Artistic Licence, +?RCS: You may redistribute only under the terms of the Artistic License, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of -?RCS: that same Artistic Licence; a copy of which may be found at the root +?RCS: that same Artistic License; a copy of which may be found at the root ?RCS: of the source tree for dist 4.0. ?RCS: ?RCS: $Log: charsize.U,v $ @@ -15,7 +15,7 @@ ?RCS: Revision 3.0 1993/08/18 12:05:34 ram ?RCS: Baseline for dist 3.0 netwide release. ?RCS: -?MAKE:charsize: cat rm Myread +cc +ccflags +?MAKE:charsize: Assert Myread cat rm +cc +ccflags echo n c ?MAKE: -pick add $@ %< ?S:charsize: ?S: This variable contains the value of the CHARSIZE symbol, which @@ -25,34 +25,40 @@ ?C: This symbol contains the size of a char, so that the C preprocessor ?C: can make decisions based on it. ?C:. -?H:#define CHARSIZE $charsize /**/ +?H:#define CHARSIZE $charsize ?H:. -?F:!try +?T:size s : check for length of character echo " " -case "$charsize" in -'') - echo "Checking to see how big your characters are..." >&4 - $cat >try.c <<'EOCP' -#include <stdio.h> +$echo $n "Checking to see how big your characters are...$c" >&4 +for size in 1 2 4 8 error; do + $cat >try.c <<EOCP +#include "static_assert.h" +char foo; int main() { - printf("%d\n", sizeof(char)); + STATIC_ASSERT($size == sizeof(foo)); + return 0; } EOCP - if $cc $ccflags -o try try.c >/dev/null 2>&1 ; then - dflt=`./try` - else - dflt='1' - echo "(I can't seem to compile the test program. Guessing...)" - fi + if $cc -c $ccflags try.c >/dev/null 2>&1; then break; fi +done +case "$size" in +error) + echo " cannot compute it." >&4 + dflt=1 + rp="What is the size of a character (in bytes)?" + . ./myread + charsize="$ans" ;; *) - dflt="$charsize" + case "$size" in + 1) s='';; + *) s='s';; + esac + echo " $size byte$s." >&4 + charsize=$size ;; esac -rp="What is the size of a character (in bytes)?" -. ./myread -charsize="$ans" -$rm -f try.c try +$rm -f try.* |