From: Josh Triplett <josh@freedesktop.org>
To: linux-sparse@vger.kernel.org
Subject: Variable "combinations" in tokenize.c and token.h
Date: Tue, 01 May 2007 14:29:10 -0700 [thread overview]
Message-ID: <4637B126.7050100@freedesktop.org> (raw)
[-- 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 --]
next reply other threads:[~2007-05-01 21:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 21:29 Josh Triplett [this message]
2007-05-01 21:27 ` Variable "combinations" in tokenize.c and token.h Christopher Li
2007-05-02 4:56 ` Josh Triplett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4637B126.7050100@freedesktop.org \
--to=josh@freedesktop.org \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.