__builtin_types_compatible_p and 'char *' vs. 'char []'

Matthew Woehlke mw_triad@users.sourceforge.net
Fri Nov 7 17:20:00 GMT 2008


Kevin P. Fleming wrote:
> Matthew Woehlke wrote:
>> Ah, yes, inline better than macro :-). I'd note that, from your example
>> usage, it sounds like your return should also be const.
> 
> No, we have to return non-const, because many uses of this
> macro/function are putting the result in a non-const variable. Returning
> non-const is safe even if the lvalue accepting the result is const, but
> the reverse generates a warning.

Yes, but if you're feeding const strings into something that strips the 
const to avoid a warning, then you're ignoring the warning at your own 
peril. You'd do better to make your code correctly const-safe. If you 
have legitimate instances where the result both needs to be non-const, 
and really /is/ non-const, then you might want to consider making a 
second version, so you have two versions, one all-const, and one 
all-non-const.

-- 
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
-- 
No .sig for you! NEXT! -- Unknown



More information about the Gcc-help mailing list