[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#517653: gcc-4.3: "warning: comparison with string literal results in unspecified behavior" when comparing two different literals



On Sun, Mar 01, 2009 at 10:40:40AM +0200, Kalle Olavi Niemitalo wrote:
> Compiling this with gcc-4.3 -Wall -c
> 
> int
> main (void)
> {
>   return "hello" == "there";
> }
> 
> results in a warning:
> 
> hoh.c: In function ???main???:
> hoh.c:4: warning: comparison with string literal results in unspecified behavior
> 
> The warning claims the behaviour is unspecified.
> But actually this comparison must always evaluate to false
> because the strings consist of different characters and
> must thus have different addresses.
> 
> For whatever reason, there are several comparisons like that
> in net-snmp 5.2.3-7etch4.

I can't imagine any sensible code whatsoever that triggers this
warning but does not have logical errors. Can you show how it is used?

  Falk



Reply to: