| Sign In/My Account | View Cart |
| Article: |
Strings in Cocoa: Part I | |
| Subject: | Comparing strings | |
| Date: | 2001-07-02 07:41:35 | |
| From: | canyonrat | |
|
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 both my memory and Help Viewer agree that gcc pools strings by default.
|
||
Showing messages 1 through 5 of 5.
Comparing strings
> 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.