From: H.Merijn Brand Date: Fri, 6 Nov 2009 06:56:01 +0000 (+0100) Subject: Detection (and warning) of char size in bits X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c193ef60f6a5fd42aabc316c80c3fc0f431e71ad;p=p5sagit%2Fp5-mst-13.2.git Detection (and warning) of char size in bits --- diff --git a/Configure b/Configure index f1123f3..25ce689 100755 --- a/Configure +++ b/Configure @@ -28,7 +28,7 @@ # $Id: Head.U 6 2006-08-25 22:21:46Z rmanfredi $ # -# Generated on Thu Nov 5 21:01:50 CET 2009 [metaconfig 3.5 PL0] +# Generated on Fri Nov 6 07:43:05 CET 2009 [metaconfig 3.5 PL0] # (with additional metaconfig patches by perlbug@perl.org) cat >c1$$ <&4 + $cat >try.c < +#$i_stdlib I_STDLIB +#ifdef I_STDLIB +#include +#endif +int main() +{ + printf("%d\n", (int)sizeof(char)); + exit(0); +} +EOCP + set try + if eval $compile_ok; then + dflt=`$run ./try` + else + dflt='1' + echo "(I can't seem to compile the test program. Guessing...)" + fi + ;; +*) + dflt="$charsize" + ;; +esac +rp="What is the size of a character (in bytes)?" +. ./myread +charsize="$ans" +$rm_try + +: Check for the number of bits in a character +case "$charbits" in +'') echo "Checking how long a character is (in bits)..." >&4 + $cat >try.c < +int main () +{ + int n; + unsigned char c; + for (c = 1, n = 0; c; c <<= 1, n++) ; + printf ("%d\n", n); + return (0); + } +EOCP + set try + if eval $compile_ok; then + dflt=`$run ./try` + else + dflt='8' + echo "(I can't seem to compile the test program. Guessing...)" + fi + ;; +*) + dflt="$charbits" + ;; +esac +rp="What is the length of a character (in bits)?" +. ./myread +charbits="$ans" +$rm_try +case "$charbits" in +8) ;; +*) cat >&4 << EOM +Your system has an unsigned character size of $charbits bits, which +is rather unusual (normally it is 8 bits). Perl likely will not work +correctly on your system, with subtle bugs in various places. +EOM + rp='Do you really want to continue?' + dflt='n' + . ./myread + case "$ans" in + [yY]) echo >&4 "Okay, continuing." ;; + *) exit 1 ;; + esac +esac + : how do we concatenate cpp tokens here? echo " " echo "Checking to see how your cpp does stuff like concatenate tokens..." >&4 @@ -22213,6 +22295,8 @@ ccversion='$ccversion' cf_by='$cf_by' cf_email='$cf_email' cf_time='$cf_time' +charbits='$charbits' +charsize='$charsize' chgrp='$chgrp' chmod='$chmod' chown='$chown' diff --git a/Cross/config.sh-arm-linux b/Cross/config.sh-arm-linux index 61011ab..9c9c396 100644 --- a/Cross/config.sh-arm-linux +++ b/Cross/config.sh-arm-linux @@ -64,6 +64,7 @@ ccversion='' cf_by='red' cf_email='red@criticalintegration.com' cf_time='Wed Sep 3 22:24:58 EDT 2003' +charbits='8' chgrp='' chmod='chmod' chown='' diff --git a/NetWare/config.wc b/NetWare/config.wc index 533a59f..e63d41c 100644 --- a/NetWare/config.wc +++ b/NetWare/config.wc @@ -51,6 +51,7 @@ ccsymbols='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown='' diff --git a/Porting/Glossary b/Porting/Glossary index 167d4d3..b810a7f 100644 --- a/Porting/Glossary +++ b/Porting/Glossary @@ -249,6 +249,14 @@ cf_time (cf_who.U): Holds the output of the "date" command when the configuration file was produced. This is used to tag both config.sh and config_h.SH. +charbits (charsize.U): + This variable contains the value of the CHARBITS symbol, which + indicates to the C program how many bits there are in a character. + +charsize (charsize.U): + This variable contains the value of the CHARSIZE symbol, which + indicates to the C program how many bytes there are in a character. + chgrp (Loc.U): This variable is defined but not used by Configure. The value is the empty string and is not useful. diff --git a/Porting/config.sh b/Porting/config.sh index c18faa4..ab0a29b 100644 --- a/Porting/config.sh +++ b/Porting/config.sh @@ -77,6 +77,7 @@ ccversion='' cf_by='merijn' cf_email='yourname@yourhost.yourplace.com' cf_time='Wed Jan 23 09:43:56 CET 2008' +charbits='8' chgrp='' chmod='chmod' chown='' diff --git a/config_h.SH b/config_h.SH index ccb7f10..ff4c860 100755 --- a/config_h.SH +++ b/config_h.SH @@ -2943,6 +2943,12 @@ sed <$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un #define BYTEORDER 0x$byteorder /* large digits for MSB */ #endif /* NeXT */ +/* CHARBITS: + * This symbol contains the size of a char, so that the C preprocessor + * can make decisions based on it. + */ +#define CHARBITS $charbits /**/ + /* CASTI32: * This symbol is defined if the C compiler can cast negative * or large floating point numbers to 32-bit ints. diff --git a/configure.com b/configure.com index d5ea932..934633e 100644 --- a/configure.com +++ b/configure.com @@ -5854,6 +5854,7 @@ $ WC "ccversion='" + ccversion + "'" $ WC "cf_by='" + cf_by + "'" $ WC "cf_email='" + cf_email + "'" $ WC "cf_time='" + cf_time + "'" +$ WC "charbits='8'" $ WC "config_args='" + config_args + "'" $ WC "config_sh='" + config_sh + "'" $ WC "cpp_stuff='" + cpp_stuff + "'" diff --git a/epoc/config.sh b/epoc/config.sh index 8623a85..57dc276 100644 --- a/epoc/config.sh +++ b/epoc/config.sh @@ -58,6 +58,7 @@ ccsymbols='' cf_by='olaf' cf_email='o.flebbe@gmx.de' cf_time='Dec 2001' +charbits='8' chgrp='' chmod='' chown='' diff --git a/plan9/config_sh.sample b/plan9/config_sh.sample index 763f7aa..0fba47e 100644 --- a/plan9/config_sh.sample +++ b/plan9/config_sh.sample @@ -64,6 +64,7 @@ ccversion='' cf_by='9trouble' cf_email='9trouble@plan9.bell-labs.com' cf_time='Sun Nov 24 20:57:48 EST 2002' +charbits='8' chgrp='' chmod='chmod' chown='' diff --git a/symbian/config.sh b/symbian/config.sh index 9885d4d..a7eda34 100644 --- a/symbian/config.sh +++ b/symbian/config.sh @@ -22,6 +22,7 @@ cccdlflags='' ccdlflags='' cf_by='root@localhost' cf_time='Thu Jan 1 00:00:00 GMT 1970' +charbits='8' clocktype='clock_t' cpp_stuff='42' cpplast='' diff --git a/uconfig.sh b/uconfig.sh index f4cefcb..7d67f19 100755 --- a/uconfig.sh +++ b/uconfig.sh @@ -15,6 +15,7 @@ byteorder='1234' castflags='0' cf_by='root@localhost' cf_time='Thu Jan 1 00:00:00 GMT 1970' +charbits='8' clocktype='clock_t' cpplast='-' cppminus='-' diff --git a/win32/config.bc b/win32/config.bc index 6743f14..ed5654a 100644 --- a/win32/config.bc +++ b/win32/config.bc @@ -51,6 +51,7 @@ ccversion='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown='' diff --git a/win32/config.ce b/win32/config.ce index cee1175..9bbbe28 100644 --- a/win32/config.ce +++ b/win32/config.ce @@ -51,6 +51,7 @@ ccsymbols='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown='' diff --git a/win32/config.gc b/win32/config.gc index 018f174..5199e26 100644 --- a/win32/config.gc +++ b/win32/config.gc @@ -51,6 +51,7 @@ ccversion='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown='' diff --git a/win32/config.vc b/win32/config.vc index e0c6354..b66c334 100644 --- a/win32/config.vc +++ b/win32/config.vc @@ -51,6 +51,7 @@ ccversion='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown='' diff --git a/win32/config.vc64 b/win32/config.vc64 index 44ab7f2..bf80c7b 100644 --- a/win32/config.vc64 +++ b/win32/config.vc64 @@ -51,6 +51,7 @@ ccversion='' cf_by='nobody' cf_email='nobody@no.where.net' cf_time='' +charbits='8' chgrp='' chmod='' chown=''