[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Minor nit about usage of sizeof(char)
- From: roberto@... (Roberto Ierusalimschy)
- Date: Fri, 9 Nov 2007 12:20:10 -0200
> >> This appears a few times in Lua sources.
> >> But its per definition 1.
> >And every C compiler in the world will optimise it as such at compile
> >time. Just like expressions like strlen("a literal string") are
> >optimised during compile time.
> I know. But when seeing this I always get suspicious if the original
> author really wanted to write CHAR_BIT/8.
sizeof(char) is always 1, by definition:
When applied to an operand that has type char, unsigned char, or signed
char, (or a qualified version thereof) the result is 1.
CHAR_BIT does not need to be 8 (8 is its smaller value in ANSI C). Unless
you are manipulating bits, you seldom need CHAR_BIT.