This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Regression with strn-stuff
Nick Clifton escreveu:
Hans-Peter wrote:
Gotta find a way to automatically check the const-stringness of
the second operand. Use __builtin_constant_p in a checking
macro enabled for gcc?
Is there such a function ? I did not know, but if it does exist then
yes, using it would be a good idea.
In my original:
#define const_strcmp(DST, ORG) \
strncmp (DST, ORG "", sizeof (ORG) - 1)
The double double-quotes ("") were there to check if the parameter
was a compile time const string, since it is legal in C to write a
string this way:
("string part 1" "string part 2").
I had played with __builtin_constant_p too, but since it was gcc
specific I dropped it.
Isn't the double quotes version OK?
The double double-quotes ) version only doesn't work when you pass
CONST_STRNEQ a string inside parentheses, like in:
#define MY_STRING ("a string")
CONST_STRNEQ (a_str, MY_STRING);
Since it would expand to:
... ("a string") "" ...
, which doesn't work. But the parenthesis in this cases add no value,
so then can be safely removed.
Cheers,
Pedro Alves