lua-users home
lua-l archive

Re: Minor nit about usage of sizeof(char)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> >> 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.
-- Roberto

AltStyle によって変換されたページ (->オリジナル) /