29#ifndef _RWSTD_NO_LIMITS_H
38#ifndef _RWSTD_NO_LONG_LONG
39# define LONG_LONG long long
41# if defined (_MSC_VER)
42# define LONG_LONG __int64
49#ifndef _RWSTD_NO_HONOR_STD
50# ifdef _RWSTD_NO_STD_TERMINATE
69 bool is_max,
const char *type)
75 char nstr [64] = { 0 };
77 char* pnstr = nstr +
sizeof nstr - 2;
79 const char digit [] = {
80 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
83 if (is_max ||
n >=
zero) {
87 *--pnstr = digit [tnstr % 16];
89 *--pnstr = digit [tnstr % 16];
98 &&
'\0' == type [4]) {
102 nstr [
sizeof nstr - 2] =
'\'';
108 char macro_name [64];
109 char macro_value [64];
112 sprintf (macro_name,
"_RWSTD_%s_MAX", pfx);
113 sprintf (macro_value,
"%s%s", pnstr, sfx);
117 sprintf (macro_name,
"_RWSTD_%s_MIN ", pfx);
121 sprintf (macro_value,
"-_RWSTD_%s_MAX", pfx);
124 sprintf (macro_value,
"(-_RWSTD_%s_MAX - 1%s)", pfx, sfx);
128 sprintf (macro_value,
"%s%s", pnstr, sfx);
132 printf (
"#define %-18s %s\n", macro_name, macro_value);
161#ifndef _RWSTD_NO_LONG_LONG
165# if defined (_MSC_VER)
167const char*
type_suffix (
unsigned __int64) {
return "UL"; }
185 for (*pval =
max / (
two +
two); *pval; ) {
219 for (
unsigned char c =
'\01';
c;
c <<= 1, ++bits);
221 printf (
"#define _RWSTD_CHAR_BIT %2u\n", bits);
232#define SIZEOF(T) unsigned (sizeof (T))
244#ifndef _RWSTD_NO_BOOL
245 printf (
"#define _RWSTD_BOOL_SIZE %2u /* sizeof (bool) */\n",
249 printf (
"#define _RWSTD_CHAR_SIZE %2u /* sizeof (char) */\n",
251 printf (
"#define _RWSTD_SHRT_SIZE %2u /* sizeof (short) */\n",
253 printf (
"#define _RWSTD_INT_SIZE %2u /* sizeof (int) */\n",
255 printf (
"#define _RWSTD_LONG_SIZE %2u /* sizeof (long) */\n",
258 printf (
"#define _RWSTD_FLT_SIZE %2u /* sizeof (float) */\n",
260 printf (
"#define _RWSTD_DBL_SIZE %2u /* sizeof (double) */\n",
263#ifndef _RWSTD_NO_LONG_DOUBLE
264 printf (
"#define _RWSTD_LDBL_SIZE %2u /* sizeof (long double) */\n",
269 printf (
"#define _RWSTD_PTR_SIZE %2u /* sizeof (void*) */\n",
272 typedef void (*fun_ptr_t)();
273 printf (
"#define _RWSTD_FUNPTR_SIZE %2u /* sizeof (void(*)()) */\n",
277 printf (
"#define _RWSTD_MEMPTR_SIZE %2u "
278 "/* sizeof (void (struct::*)()) */\n",
285#ifndef _RWSTD_NO_BOOL
287 printf (
"#define _RWSTD_BOOL_MIN !!0\n");
288 printf (
"#define _RWSTD_BOOL_MAX !0\n");
297 printf (
"#define _RWSTD_NO_TWOS_COMPLEMENT\n");
299#define MKLIMITS(T, pfx, sfx, type) \
302 compute_limits (&buf, pfx, sfx, type); \
305 MKLIMITS (
char,
"CHAR",
"",
"char");
306 MKLIMITS (
signed char,
"SCHAR",
"",
"signed char");
307 MKLIMITS (
unsigned char,
"UCHAR",
"U",
"unsigned char");
309 MKLIMITS (
short,
"SHRT",
"",
"short");
310 MKLIMITS (
unsigned short,
"USHRT",
"U",
"unsigned short");
313 MKLIMITS (
unsigned int,
"UINT",
"U",
"unsigned int");
315 MKLIMITS (
long,
"LONG",
"L",
"long");
316 MKLIMITS (
unsigned long,
"ULONG",
"UL",
"unsigned long");
318#ifndef _RWSTD_NO_LONG_LONG
320# define LLong long long
324 const char llong_name[] =
"long long";
327 MKLIMITS (
unsigned LLong,
"ULLONG",
"ULL",
"unsigned long long");
331# if defined (_MSC_VER)
333# define LLong __int64
337 const char llong_name[] =
"__int64";
340 MKLIMITS (
unsigned LLong,
"ULLONG",
"UL",
"unsigned __int64");
346 const char llong_name[] =
"long";
352#ifndef _RWSTD_NO_WCHAR_T
354 printf (
"#define _RWSTD_WCHAR_SIZE %2u /* sizeof (wchar_t) */\n",
357 const char *suffix =
"U";
358 if ((
wchar_t)~0 < (
wchar_t)0)
361 MKLIMITS (
wchar_t,
"WCHAR", suffix,
"wchar_t");
365#if defined (MB_LEN_MAX)
367 printf (
"#define _RWSTD_MB_LEN_MAX %d /* libc value */\n",
373 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known AIX libc value */\n", 4);
374# elif defined (__hpux)
375 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known HP-UX libc value */\n", 4);
376# elif defined (__sgi) || defined (sgi)
377 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known IRIX libc value */\n", 5);
378# elif defined (__GLIBC__) && __GLIBC_MINOR__ <= 1
379 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known glibc 2.1 value */\n", 6);
380# elif defined (__GLIBC__) && __GLIBC_MINOR__ >= 2
381 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known glibc 2.2 value */\n", 16);
382# elif defined (__sun__) || defined (__sun) || defined (__sun)
383 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known SunOS libc value */\n", 5);
384# elif defined (_WIN32)
385 printf (
"#define _RWSTD_MB_LEN_MAX %d /* known WIN32 libc value */\n", 5);
387 printf (
"#define _RWSTD_MB_LEN_MAX %d /* guess */\n", 8);
400#define PRINT_SPECIFIC(width, least, type) \
403 const char* least_str = least; \
404 if (least_str && *least_str) \
405 printf ("#define _RWSTD_INT_LEAST%d_T %s _RWSTD_%s_T\n" \
406 "#define _RWSTD_UINT_LEAST%d_T %s _RWSTD_U%s_T\n", \
407 width, width < 10 ? " " : "", type, \
408 width, width < 10 ? " " : "", type); \
410 printf ("#define _RWSTD_INT%d_T %s signed %s\n" \
411 "#define _RWSTD_UINT%d_T %s unsigned %s\n", \
412 width, width < 10 ? " " : "", type, \
413 width, width < 10 ? " " : "", type); \
416 if (8 == char_bits) {
420 else if (16 == char_bits) {
424 else if (32 == char_bits) {
428 else if (64 == char_bits) {
433 if (16 == char_bits *
sizeof (
short) && !(width_bits & 2)) {
437 else if (32 == char_bits *
sizeof (
short) && !(width_bits & 4)) {
441 else if (64 == char_bits *
sizeof (
short) && !(width_bits & 8)) {
445 else if (128 == char_bits *
sizeof (
short) && !(width_bits & 16)) {
450 if (32 == char_bits *
sizeof (
int) && !(width_bits & 4)) {
454 else if (64 == char_bits *
sizeof (
int) && !(width_bits & 8)) {
458 else if (128 == char_bits *
sizeof (
int) && !(width_bits & 16)) {
463 if (32 == char_bits *
sizeof (
long) && !(width_bits & 4)) {
467 else if (64 == char_bits *
sizeof (
long) && !(width_bits & 8)) {
471 else if (128 == char_bits *
sizeof (
long) && !(width_bits & 16)) {
476 if (32 == char_bits *
sizeof (
LLong) && !(width_bits & 4)) {
480 else if (64 == char_bits *
sizeof (
LLong) && !(width_bits & 8)) {
485 else if (128 == char_bits *
sizeof (
LLong) && !(width_bits & 16)) {
494 if (width_bits & (1 << 0))
496 else if (width_bits & (1 << 1))
498 else if (width_bits & (1 << 2))
500 else if (width_bits & (1 << 3))
502 else if (width_bits & (1 << 4))
505 if (width_bits & (1 << 1))
507 else if (width_bits & (1 << 2))
509 else if (width_bits & (1 << 3))
511 else if (width_bits & (1 << 4))
514 if (width_bits & (1 << 2))
516 else if (width_bits & (1 << 3))
518 else if (width_bits & (1 << 4))
521 if (width_bits & (1 << 3))
523 else if (width_bits & (1 << 4))
526 if (width_bits & (1 << 4))
IMPORT_C SInt32 printf(const Char *,...)
#define MKLIMITS(T, pfx, sfx, type)
volatile int zero_complement
const char * type_suffix(T)
unsigned compute_char_bits()
void print_limit(T n, const char *pfx, const char *sfx, bool is_max, const char *type)
#define PRINT_SPECIFIC(width, least, type)
T compute_limits(T *pval, const char *pfx, const char *sfx, const char *type)