This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ PATCH to fix thinko


This sort of macro absolutely needs the string to be a constant. If a
char pointer is passed in the code will be syntactically correct, but
invalid.

Perhaps the name could be something like matchstrconst.

Trevor
Gabriel Dos Reis wrote:
> 
> Zack Weinberg <zack@wolery.cumb.org> writes:
> 
> | On Mon, May 15, 2000 at 08:44:50PM +0200, Gabriel Dos Reis wrote:
> | > Manfred Hollstein <manfred.h@gmx.net> writes:
> | >
> | > | I believe, using constants as the length argument to strncmp
> | > | is error prone; I'd suggest to use this instead:
> | > |
> | > |    else if (!strncmp (p, "diagnostics-show-location=",
> | > |                 sizeof ("diagnostics-show-location=") - 1))
> | >
> | > 100% agreed.
> |
> | I like to go a bit farther:
> 
> But then let's go much farther :-)
> 
> How about
> 
> #define match(PTR, STRING) (!strncmp (PTR, STRING, sizeof (STRING) -1))
> 
> used as:
> 
>   else if (match (p, "diagnostics-show-location="))
> 
> ?
> 
> -- Gaby
> CodeSourcery, LLC                             http://www.codesourcery.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]