advertisement

Article:
  Strings in Cocoa: Part I
Subject:   Comparing strings
Date:   2001-07-03 14:38:00
From:   wcray
Response to: Comparing strings

> Actually, comparing string1 and string2
> with == didn't work
> when I compiled Mike's code fragment as
> a standard tool.
> This is surprising because...


Actually not unexpected. string1 and string2
were declared as unbounded char arrays, which
gcc assumes aren't constant strings (while
type char *s with initializers are assumed
to be constant).


I believe the logic is that


char foo[] = "yabba dabba";


declares foo to be a character array, and
then the initializer puts data into it, while


char *foo2 = "yabba dabba";


declares foo2 to be a pointer, and the
initializer points it to a string containing
"yabba dabba" that already exists in
the memory space.


1 to 2 of 2
  1. Comparing strings
    2001-07-03 16:44:43  canyonrat [View]

    • Comparing strings
      2001-07-04 18:36:41  bigboytoddy [View]

      • Comparing strings
        2001-07-04 23:33:56  canyonrat [View]

  2. Michael Beam photo Comparing strings
    2001-07-03 15:53:58  Michael Beam | O'Reilly Author [View]

1 to 2 of 2