This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Warning from cpp on macro argument stringification is missing
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Warning from cpp on macro argument stringification is missing
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Thu, 7 Sep 2000 13:21:03 -0700
- Cc: NeilB at earthling dot net, gcc-bugs at gcc dot gnu dot org
- References: <200009071917.PAA02371@caip.rutgers.edu>
On Thu, Sep 07, 2000 at 03:17:13PM -0400, Kaveh R. Ghazi wrote:
>
> Ugh, it's as I feared.
>
> Okay, I got as far as that on my own. When I added the CPP_STRING and
> CPP_CHAR cases in save_expansion, the relevant string came up in
> token->val.str.text. As you say, the nasty part is that I have to
> tokenize the string. E.g. given:
>
> > #define foo(A, hello, E) "A B hello C,hello,DhelloE"
>
> I suppose I have to warn about `A', and the first two `hello's but not
> the third `hello' or the 'E' since they are not standalone tokens and
> wouldn't get replaced in traditional C. (Right?)
Right.
> That means chopping up the string at ID separators and checking each
> token against each function macro parameter.
>
> Sooo, what's the best way to do that? Is there some handy routine in
> cpplex.c to tokenize arbitrary strings or should I dup the string and
> use strtok?
You shouldn't need to split up the string. Something like this should
do fine:
U_CHAR *p, *q;
for (p = string; p < limit; p = q) {
while(!is_idstart(*p)) p++;
q = p;
while(is_idchar(*q)) q++;
for(i = 0; i < nargs; i++)
if(argv[i].len == q - p && !memcmp(p, argv[i].str, q - p))
issue warning;
}
- flesh out with checks for running off the end of the string as
appropriate. IIRC, ->val.str.text is not nul-terminated.
zw