[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-grep] length of dec. representation of a number
From: |
Aharon Robbins |
Subject: |
Re: [bug-grep] length of dec. representation of a number |
Date: |
Thu, 24 Feb 2005 17:13:55 +0200 |
> Date: Thu, 24 Feb 2005 14:54:09 +0100
> From: Stepan Kasal <address@hidden>
> Subject: [bug-grep] length of dec. representation of a number
> To: address@hidden
>
>
> Hello,
> I'm going to check in the following small patch.
> Stepan
>
> - char buf[sizeof pos * CHAR_BIT];
> + char buf[(sizeof pos + 1) / 2 * 5 + 1]; /* log_10(2^16) < 5 */
Ahem. Try something like this, please?
#define MAX_DEC_DIGITS_FOR(VAR) ((sizeof VAR + 1) / 2 * 5 + 1) /*
log_10(2^16) << 5 */
(I assume that in the comment you meant `<< 5' and not `< 5' which is
a boolean test.) Then:
char buf[MAX_DEC_DIGITS_FOR(pos)];
and
char buf[MAX_DEC_DIGITS_FOR(uintmax_t)];
Really, you should know better.
Arnold