<<< Date Index >>>     <<< Thread Index >>>

Re: Few warnings in cvs



Hi,

On 2006-11-17 09:26:40 +0000, Rocco Rutte wrote:
> Int is simply too large with its 4 bytes. uint8_t is supposed to be 1 
> byte only... and when CHAR_CLASS_MAX_LENGTH is 255, this is sufficient.  

A type used for computations (and not storing) is never too large.
If some values are never used, this is fine. Now, are you sure that
CHAR_CLASS_MAX_LENGTH is 255? The code has:

# ifdef CHARCLASS_NAME_MAX
#  define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
# else
/* This shouldn't happen but some implementation might still have this
   problem.  Use a reasonable default value.  */
#  define CHAR_CLASS_MAX_LENGTH 256
# endif

and under Linux (Debian unstable), /usr/include/bits/posix2_lim.h
contains:

#ifndef CHARCLASS_NAME_MAX
#define CHARCLASS_NAME_MAX      2048
#endif

> And sizeof(char) is usually 1 (byte), too.

It must be 1 (but CHAR_BIT is not necessarily 8).

> Also as it seems, the c1 variable is reused deeply within the code (also 
> as a real char) so declaring it once for many cases also saves a little 
> memory and/or moving the stack pointer.

It doesn't save anything as compilers can now optimize very well.
On the contrary, it is better to have a small scope for variables
and avoid reuse of more global variables. Moreover, due to integer
promotions, doing operations on unsigned chars may lead to larger
code size, as masking code may be necessary.

> If you cleverly place a uint8_t with some more of these smaller 
> parameters, it may save a few bytes memory since the compiler can 
> internally pack them into just one int (like it does for all the bit 
> fields mutt uses for its structures).

This may be true for variables that need to be stored into memory,
but here it was just a loop index, that should generally be kept in
a register. Of course, if variables are reused more than necessary,
it is much more difficult for a compiler to do such optimizations.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)