pete wrote:
int main(void)
{
char a[(size_t)((sizeof(int) * CHAR_BIT - 1) / 3.3) + 3];
char b[(size_t)((sizeof(int) * CHAR_BIT - 1) / 3.3) + 3];
char c[(size_t)((sizeof(int) * CHAR_BIT - 1) / 3.3) + 3];
(to allocate enough space for a conversion to decimal)
A question: is that valid C89, too? gcc accepts it
with -std=c89 -pedantic-errors, but I was under the impression that integer
constant expressions could not contain floating point arithmetic.
I think you're right and it's not allowed/guaranteed by the Standard.
But there is also an 'escape clause' that 'An implementation may
accept other forms of constant expressions.' It doesn't specifically
apply this to i.c.e.s but it doesn't exclude it either.
Maybe gcc already folded the constant down to (size_t)9.4 + 3,
which does satisfy the Standard's description, before checking.
OTOH, I see no great need to compute this so exactly. I usually just
use nbits / 3 + slop, which is IMJ easier to write and to read: I
think it as 'space for octal, which is also plenty for decimal'.
- David.Thompson1 at worldnet.att.net