(Jens Thoms Toerring) writes:
> mt <> wrote:
>> A pointer in an if statement is normal, and may have many meanings,
>> not just limited to non-null. It may mean
>> - whether two pointers are the same;
>> - whether the pointer pointed value is a special value, like
>> if((*p)==1);
>> - if the pointer is char *, more string related function calling may
>> appeared, like if(strcmp(a,b))
>
>> what else does it mean?
>
> Your question doesn't make much sense to me. In an if condition
> you need an expression that has a boolean value (or a value that
> can be converted into a boolean value). And that expression can,
> of course, contain one or more pointers. The number of such ex-
> pressions you can construct is rather large (I guess mostly li-
> mited by the finite amount of storage available when compiling a
> program). So "what else does it mean" is a bit difficult to ans-
> wer. Could you rephrase the question a bit so that it becomes
> clearer what it's all about?
Strictly speaking, an if condition can be any scalar expression.
The condition is true if the expression compares unequal to zero
(that's basically 0 for integer types, 0.0 for floating-point types,
NULL for pointer types).
But yes, I'm also having trouble figuring out just what the OP
is asking.
I suppose you could enumerate the contexts in which an expression
of pointer type can appear in a condition (by itself, as the operand
of a "[]", "-", or "+" operator, as an argument in a function call,
as the LHS or RHS of an assignment, etc.). That's certainly easier
than enumerating *all* the possible ways (p + 1, p + 2, ..., p +
0xdeadbeef), but I frankly don't see the use of it.
mt, can you clarify what you're looking for?
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"