Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C question

Reply
Thread Tools

C question

 
 
mt
Guest
Posts: n/a
 
      08-05-2011
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?
 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      08-05-2011
mt <(E-Mail Removed)> 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 ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      08-05-2011
(E-Mail Removed) (Jens Thoms Toerring) writes:
> mt <(E-Mail Removed)> 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) (E-Mail Removed) <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"
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      08-06-2011
mt <(E-Mail Removed)> 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.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-06-2011
http://www.velocityreviews.com/forums/(E-Mail Removed)-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) (E-Mail Removed) <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"
 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      08-10-2011
On Aug 5, 9:59*pm, mt <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments