linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Variable "combinations" in tokenize.c and token.h
@ 2007-05-01 21:29 Josh Triplett
  2007-05-01 21:27 ` Christopher Li
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Triplett @ 2007-05-01 21:29 UTC (permalink / raw)
  To: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

token.h contains this:
> /* Combination tokens */
> #define COMBINATION_STRINGS {   \
>         "+=", "++",             \
>         "-=", "--", "->",       \
>         "*=",                   \
>         "/=",                   \
>         "%=",                   \
>         "<=", ">=",             \
>         "==", "!=",             \
>         "&&", "&=",             \
>         "||", "|=",             \
>         "^=", "##",             \
>         "<<", ">>", "..",       \
>         "<<=", ">>=", "...",    \
>         "",                     \
>         "<", ">", "<=", ">="    \
> }
> 
> extern unsigned char combinations[][3];

tokenize.c contains this:
> const char *show_special(int val)
> {
>         static const char *combinations[] = COMBINATION_STRINGS;
>         static char buffer[4];
> 
>         buffer[0] = val;
>         buffer[1] = 0;
>         if (val >= SPECIAL_BASE)
>                 strcpy(buffer, combinations[val - SPECIAL_BASE]);
>         return buffer;
> }
[...]
> unsigned char combinations[][3] = COMBINATION_STRINGS;

Apart from triggering a -Wshadow warning, this seems somewhat wasteful.
The reason appears to relate to the presence or absence of a '\0'
terminator at the end of each item.  Does that matter?  Could
show_special change somehow to avoid the duplication?  Alternatively,
could the global version just include '\0' terminators?

- Josh Triplett


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-02  4:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 21:29 Variable "combinations" in tokenize.c and token.h Josh Triplett
2007-05-01 21:27 ` Christopher Li
2007-05-02  4:56   ` Josh Triplett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).