develooper Front page | perl.perl5.porters | Postings from November 2009

Re: [PATCH] Configure to check for 8-bit bytes

Thread Previous
From:
Zefram
Date:
November 1, 2009 04:41
Subject:
Re: [PATCH] Configure to check for 8-bit bytes
Message ID:
20091101124104.GC403@fysh.org
H.Merijn Brand wrote:
>2. It just tests on UCHAR_MAX == 255 (what if 9bit-byte systems don't
>   have limits.h or don't define UCHAR_MAX ?

If you're actually running (rather than just compiling or preprocessing)
code for this test, you might as well be empirical about it:

	#include <stdio.h>
	int main(void) {
		int n;
		unsigned char c;
		for(c=1, n=0; c; c<<=1, n++) ;
		printf("CHAR_BITS=%d\n", n);
		return 0;
	}

The arithmetical behaviour of unsigned char is sufficiently guaranteed
by the C standard for this to always be correct.

-zefram

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About