Hi Jim,
> +# define inttostr(n, s) \
> + ((void) verify_true (sizeof (s) == sizeof (void *) \
> + || INT_BUFSIZE_BOUND (int) <= sizeof (s)), \
> + (inttostr) (n, s))
Nice and clever trick.
Unfortunately, it does not work for variable-length arrays, which are allowed
in C99 and C++.
Test case:
void foo (int n)
{
char buf[10 + (n < 0) + 1];
char *result = inttostr (n, buf);
}
Yields:
foo.c: In function ‘foo’:
foo.c:38: error: bit-field ‘verify_error_if_negative_size__’ width not an
integer constant
How to fix this? I tried __builtin_constant_p and __builtin_choose_expr, but
haven't found the trick.
Bruno