Michael Felt wrote:
Curious why you are calling this a compiler bug.
Because it is a compiler bug. Try to compile (but not link) the
attached file. Here's what I get on AIX 7.1 with xlc 12.1 and GCC 4.8.1.
$ gcc -c xlcbug1.c
$ xlc -c xlcbug1.c
"xlcbug1.c", line 22.39: 1506-045 (S) Undeclared identifier
GL_FLT_PREC_BOUND.
"xlcbug1.c", line 22.23: 1506-1324 (S) Array size must have integer type.
There's nothing wrong with the program. The identifier is properly
declared.
What is the origin of the _GL_* identifiers?
They're from Gnulib, but that's irrelevant to the compiler bug, as the
attached file demonstrates.
#include <stdio.h>
int ftoastr (char *buf, size_t bufsize, int flags, int width, float x);
int dtoastr (char *buf, size_t bufsize, int flags, int width, double x);
int ldtoastr (char *buf, size_t bufsize, int flags, int width, long double x);
enum
{
FTOASTR_LEFT_JUSTIFY = 1,
FTOASTR_ALWAYS_SIGNED = 2,
FTOASTR_SPACE_POSITIVE = 4,
FTOASTR_ZERO_PAD = 8,
FTOASTR_UPPER_E = 16
};
enum { GL_FLT_PREC_BOUND = (((((24) * 1) * 146 + 484) / 485) + 1) };
enum { GL_DBL_PREC_BOUND = (((((53) * 1) * 146 + 484) / 485) + 1) };
enum { GL_LDBL_PREC_BOUND = (((((53) * 1) * 146 + 484) / 485) + 1) };
static int
ftoastr_snprintf (char *buf, size_t bufsize, char const *format,
int width, int prec, float x)
{
char width_0_buffer[1 == 1 ? ( (1 + GL_FLT_PREC_BOUND + 4 + 1 + ( -100 < ((-37)) && (38) < 100 ? 3 : -1000 < ((-37)) && (38) < 1000 ? 4 : -10000 < ((-37)) && (38) < 10000 ? 5 : -100000 < ((-37)) && (38) < 100000 ? 6 : -1000000 < ((-37)) && (38) < 1000000 ? 7 : ((((sizeof (int) * 8 - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) )) + 1)
: 1 == 2 ? ( (1 + GL_DBL_PREC_BOUND + 4 + 1 + ( -100 < ((-307)) && (308) < 100 ? 3 : -1000 < ((-307)) && (308) < 1000 ? 4 : -10000 < ((-307)) && (308) < 10000 ? 5 : -100000 < ((-307)) && (308) < 100000 ? 6 : -1000000 < ((-307)) && (308) < 1000000 ? 7 : ((((sizeof (int) * 8 - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) )) + 1)
: ((1 + GL_LDBL_PREC_BOUND + 4 + 1 + ( -100 < ((-307)) && (308) < 100 ? 3 : -1000 < ((-307)) && (308) < 1000 ? 4 : -10000 < ((-307)) && (308) < 10000 ? 5 : -100000 < ((-307)) && (308) < 100000 ? 6 : -1000000 < ((-307)) && (308) < 1000000 ? 7 : ((((sizeof (int) * 8 - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) )) + 1)];
int n = width;
if (bufsize < sizeof width_0_buffer)
{
n = sprintf (width_0_buffer, format, 0, prec, x);
if (n < 0)
return n;
if (n < width)
n = width;
}
if (n < bufsize)
n = sprintf (buf, format, width, prec, x);
return n;
}
int
ftoastr (char *buf, size_t bufsize, int flags, int width, float x)
{
char format[sizeof "%-+ 0*.*Lg"];
float abs_x = x < 0 ? -x : x;
int prec;
char *p = format;
*p++ = '%';
*p = '-'; p += (flags & FTOASTR_LEFT_JUSTIFY ) != 0;
*p = '+'; p += (flags & FTOASTR_ALWAYS_SIGNED ) != 0;
*p = ' '; p += (flags & FTOASTR_SPACE_POSITIVE) != 0;
*p = '0'; p += (flags & FTOASTR_ZERO_PAD ) != 0;
*p++ = '*';
*p++ = '.';
*p++ = '*';
*p = 'L'; p += 2 < 1;
*p++ = flags & FTOASTR_UPPER_E ? 'G' : 'g';
*p = '\0';
for (prec = abs_x < 1.1754943508222875e-38F ? 1 : 6; ; prec++)
{
int n = ftoastr_snprintf (buf, bufsize, format, width, prec, x);
if (n < 0
|| GL_FLT_PREC_BOUND <= prec
|| (n < bufsize && strtod (buf, ((void *)0)) == x))
return n;
}
}