C question

Discussion in 'C Programming' started by mt, Aug 5, 2011.

  1. mt

    mt Guest

    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?
    mt, Aug 5, 2011
    #1
    1. Advertising

  2. 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?
    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
    Jens Thoms Toerring, Aug 5, 2011
    #2
    1. Advertising

  3. (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) <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"
    Keith Thompson, Aug 6, 2011
    #3
  4. mt

    Stefan Ram Guest

    mt <> 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.
    Stefan Ram, Aug 6, 2011
    #4
  5. -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) <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"
    Keith Thompson, Aug 6, 2011
    #5
  6. mt

    Paul N Guest

    On Aug 5, 9:59 pm, 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?


    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.
    Paul N, Aug 10, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    576
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    638
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    932
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    407
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    822
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page