MCENANEY WILLIAM J wrote:
> Glynn has asked me how I would compare two pointers if I could replace
> "strcmp() == 0" with a relational equal sign. Suppose a pointer is only
> an address. Then could I write, "if (&s1 = &s2) . . ."? Or would that
> compare the address of s1's first character to the address of s2's
> first character?
No, that's what `s1 == s2' means. `&s1 == &s2' would compare the
addresses of the variables holding the pointers (and only applies to
lvalues, rather than arbitrary expressions such as `foo() == bar()',
where foo() and bar() both return `char *'s.
> Maybe I could create a standard function named "pointer_of." For C
> programmers, that may be a little wordy. But with it, I could say:
>
> if (pointer_of(s1) = pointer_of(s2))
> puts ("The addresses are the same.");
But pointer_of is the identity function:
void *pointer_of(void *p)
{
return p;
}
For pointers to primitive types (integers and floats), the distinction
is between `p1 == p2' and `*p1 == *p2'. Comparing strings with strcmp
is logically equivalent to the latter.
--
Glynn Clements <[EMAIL PROTECTED]>