[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

C question

mahdert

8/5/2011 9:00:00 PM

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?
5 Answers

jt

8/5/2011 10:24:00 PM

0

mt <mahdert@gmail.com> 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?
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://t...

Keith Thompson

8/5/2011 11:21:00 PM

0

jt@toerring.de (Jens Thoms Toerring) writes:
> mt <mahdert@gmail.com> 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-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

ram

8/6/2011 12:37:00 AM

0

mt <mahdert@gmail.com> writes:
>what else does it mean?

A pointer does not have a meaning (at least not
a meaning specified by ISO/IEC 9899:1999 (E)).

A pointer has all properties an object has, such
as type, value or alignment. Its type, of course,
is a pointer type.

Related terms from ISO/IEC 9899:1999 (E) are

- null pointer
- null pointer constant
- pointer type
- pointer expression
- valid pointer expression
- pointer parameter
- restricted pointer
- pointer to ... (void, functions, objects, ...)
- variable/constant pointer
- pointer to non-modifiable storage
- address

. However, I believe that ISO/IEC 9899:1999 (E) sometimes
uses »pointer« to refer to an object and sometimes to refer
to a value (for example, when it says that a pointer was
returned by a function). It would be more consistent to
always use »pointer« (for an object of pointer type) and
»address« (for a value of pointer type).

The controlling expression of an if statement shall have
scalar type, the first substatement is executed if the
expression compares unequal to 0.

Since an address (a value of pointer type) is a scalar type,
it can be the controlling expression of an if statement.

Keith Thompson

8/6/2011 1:09:00 AM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
[...]
> . However, I believe that ISO/IEC 9899:1999 (E) sometimes
> uses »pointer« to refer to an object and sometimes to refer
> to a value (for example, when it says that a pointer was
> returned by a function). It would be more consistent to
> always use »pointer« (for an object of pointer type) and
> »address« (for a value of pointer type).
[...]

I think it would be more consistent to use the phrases "pointer object",
"pointer value", and "pointer type", avoiding using the unqualified word
"pointer". (And "address" when referring to the address of an object.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

gw7rib

8/10/2011 8:51:00 PM

0

On Aug 5, 9:59 pm, mt <mahd...@gmail.com> 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?

One other possibility you may be looking for (as others have said,
your question isn't entirely clear) is that you can compare pointers
using < or >. However, this only works if the two pointers point
within the same "aggregate object", eg both within the same array.