Why do people call addresses "pointers"?

Discussion in 'C Programming' started by TTroy, Jan 31, 2005.

  1. TTroy

    TTroy Guest

    Hi,

    I'm just wondering why people/books/experts say "the function returns a
    pointer to.." or "we have to send scanf a pointer to.." instead of "the
    function returns the address of.." or "we have to send scanf the
    address of.."

    Isn't the lvalue called a POINTER TO and the (r)value called the
    ADDRESS OF?

    Why do people refer to the (r)values moving around in a program as
    pointers? (Am I missing something, or just reading too much into a
    non-issue?)

    [I've noticed that experts almost never say "address of", but often
    time beginners do... there must be something to it]
     
    TTroy, Jan 31, 2005
    #1
    1. Advertisements

  2. Pointer is just a more abstract term, while address is more
    implementational. You could for example implement C in some other
    language without an access to real addresses, by using indexes into a
    large array as pointers.
    The C standard (in most places) uses the term "pointer".

    -- Richard
     
    Richard Tobin, Jan 31, 2005
    #2
    1. Advertisements

  3. TTroy

    dandelion Guest

    AFAIK "pointer" is a logical construct, which is usually (in C) resolved
    into an adress. For most C compilers the two terms are equivalent, but this
    is not always the case. Specifically all kinds of segment constructions can
    fuzzify the issue.
    I suspect the latter.
    Address of is clearer, but not always correct.
     
    dandelion, Jan 31, 2005
    #3
  4. TTroy

    j Guest

    The value of an expression can be an address, yes. But just what does
    that tell you about the type of the value?

    An lvalue is not necessarily a pointer. Consider the following,

    int foo;

    foo = 10;

    Is foo a pointer?
    If you answered ``yes'', then I recommend you buy a book on C.
     
    j, Jan 31, 2005
    #4
  5. TTroy

    TTroy Guest

    subject of post clearly established above

    a question asked about the subject
    totally unrelated question above
    The subject of my post was pointers to & addresses of.
    Why are you presenting me with a question about an int variable?
    Several years ago I did read a book that told me that the "context" of
    a statement or sentence affects it's meaning. Have you read any
    similar books?
     
    TTroy, Jan 31, 2005
    #5
  6. TTroy

    j Guest

    You are not good at this reading business are you?
    The point of that was even though a pointer to an object
    may be used as an lvalue, not all lvalues are a pointer
    to an object. ``foo'' is an object with an object type of ``int''
    and is not a pointer to such an object.

    This answers your question ``Isn't the lvalue called a POINTER TO''
     
    j, Jan 31, 2005
    #6
  7. I think it may be you that needs to brush up on reading comprehension.
    Again, you've totally missed the context that the OP provided. That
    question was *only* withing the context of pointers and addresses.
    Though, of course, the answer turned out to be "no", your answer is
    totally irrelevant.

    To help you understand the OP's question, you can break it into the
    following two questions:
    1) When a pointer or address is used as an lvalue, is it called a "pointer"?
    2) When a pointer or address is used as a non-lvalue, is it called an
    "address"?

    (This doesn't change the answer
     
    Clark S. Cox III, Jan 31, 2005
    #7
  8. TTroy

    Chris Torek Guest

    No.

    Suppose I write:

    sizeof(int *)

    What is the parenthesized "int *" here? Is it an lvalue? Is it an
    rvalue?

    The last two questions can be safely answered with "no" and "no"
    respectively -- it is neither an lvalue nor an rvalue. The answer
    to the first question is that it is a type-name. The type named is
    "pointer to int".

    What a pointer *is*, then, is part of a type-name. Formally,
    a variable (object) of type "int *" holds a value of type "int *":

    int *p;
    ...
    p = <some expression>

    The <expression> here must have type "pointer to int", or be directly
    convert-able to that type, e.g., from malloc():

    p = malloc(N * sizeof *p); /* get room for N items */

    (here we have a value of type "void *" on the right hand side of
    the "=" assignment operator, and "void *" can be converted to "int *").

    Simple textbook examples generally start with something like:

    int i;
    int *p;
    ...
    p = &i;

    Here the unary "&" (or "address-of") operator "takes the address"
    of the ordinary variable "i", producing a value of type "pointer
    to int", pointing to i.

    If we then write either:

    ret = scanf("%d", p);
    or: ret = scanf("%d", &i);

    the same thing happens in both cases: scanf() gets, as its second
    value, the address of the variable "i": a value of type "pointer
    to int", pointing to "i". (The first value is the address of the
    first element of the array holding the sequence {'%', 'd', '\0'},
    which is a value of type "char *".)

    All values in C always have types. Most of the time, when we speak
    or write informally, we believe that both the speaker/writer and
    listener/reader already understand this and agree as to all the
    types, so we just talk about the "value part" of the <type,value>
    pair. That is, we do not go around saying:

    start i at int 0, then add int 1 each trip through the loop

    We omit the "int" part each time. If we do the same with pointers,
    we might start with something like:

    scanf("%d", &i)

    call scanf, passing as the first value a value of type "char *"
    pointing to the percent sign in the three-character array holding
    the %d format directive, and passing as the second value a value
    of type "int *" pointing to the local variable named "i"

    (the full, formal version) and end up with:

    call scanf with a pointer to "i"

    or even more colloquially:

    give scanf the address of "i"

    but these all *mean* the same thing.
    I think the last. :)
    I prefer to reserve the term "address of" for the unary-& operator
    myself, but this is something of a matter of taste.
     
    Chris Torek, Jan 31, 2005
    #8
  9. TTroy

    j Guest

    I inferred from what he said not from what he meant to say.

    Suppose we did have some function that returned a pointer
    to some object, then the value it returns is the value of that
    expression.

    If we pass a pointer to some object to scanf, we also have
    a value of an expression in this context too. Whether this
    value is then used as an lvalue within scanf is irrelevant to
    what he asked.

    From this, he follows with the question of ``isn't an lvalue a pointer to''.
    lvalues are in a completely different context from what he was
    previously talking about. lvalues designate objects! This has absolutely
    nothing to do with values of expressions. As such, my response stands
    relevant to the question ``isn't an lvalue a pointer to''. It is not my
    problem if he is incapable of expressing himself with the English
    language.
     
    j, Jan 31, 2005
    #9
  10. TTroy

    TTroy Guest

     
    TTroy, Jan 31, 2005
    #10
  11. TTroy

    j Guest

     
    j, Jan 31, 2005
    #11
  12. TTroy

    TTroy Guest

     
    TTroy, Jan 31, 2005
    #12
  13. TTroy

    j Guest

    To quote you,
    ``I'm just wondering why people/books/experts say "the function returns a
    pointer to.." or "we have to send scanf a pointer to.." instead of "the
    function returns the address of.." or "we have to send scanf the
    address of.." '' ...

    .... is a question in itself. Even without an explicit question mark.
    Which means that it is your initial question. So what is the problem?

    In fact, observe the other responses to your initial post. This question
    was the first one addressed. :)

    Why do you think that is?

    Oh, look at the inclusion of the word ``why'' near the start of that
    sentence.
    What do you think that conveys to the reader?

    Additionally, your use of ``the lvalue'' is referring to the concept here
    not to anything relating to your initial question. Unless you can provide
    reasoning as to how your initial question had anything to do with
    an lvalue. I suspect that you cannot.
     
    j, Jan 31, 2005
    #13
  14. TTroy

    TTroy Guest

    The first sentence could be taken as a "call for a response," but it's
    not a question. It could be considered "similar" to a "question" if it
    wasn't followed by an actual question that triggered the context that
    the first sentenced built up. Since I used a question to connect to
    the previous context, most people would not consider the first sentence
    as an independent "call for a response" (it's not a question period!).

    What is your point? You responded to the actual first question, not
    the first sentence (go and check).
    What does this sentence mean to you? : "He wonders 'why' idiots don't
    stop."
    Is that a question? It uses the word "why!!!"

    How about this sentence? : "It doesn't matter 'when' he'll understand
    he's an idiot, he's only out to prove supremacy in his field of
    idiocy."
    Is that a question? It uses the word "when!!!"
    Depends on whether or not the reader was a supreme idiot. Since I
    didn't intend for my target audience to include idiots, most that
    responded understood fine, except this one individual.
    English is my 4th language, and let me guess, it must be your 10+th?
    What are you talking about in the passage above? What do you mean by
    "here." You're using the word "here" without any sort of proper
    context for it built up, and you complain about my lack of clarity.

    I'm a mechanical engineer trying to learn the ins/outs of C. Just
    because you're more familiar with C than me, that doesn't give you the
    right to bash anything but my C skills (like my English).
     
    TTroy, Jan 31, 2005
    #14
  15. TTroy

    j Guest

    Different context. I referred you to your initial question which
    included ``why'' near the start of the sentence. You are making
    an inquiry as to the reasoning behind calling ``addresses'',
    ``pointers''.
    Different context.
    I think your excessive use of the word ``idiot'' makes youl ook foolish.
    You aren't showing incontravertibly that, that is true. So it has no
    bearing. :)
    It was written in response to your post. The post I was responding
    to serves as providing proper context. If I were to exclude your
    post from my response, then I would not be providing proper
    context.
    I don't care.
    Oh stop your bloody whinging. It is really off-topic for this newsgroup.
    The main point here is that your initial question,

    ``I'm just wondering why people/books/experts say "the function returns a
    pointer to.." or "we have to send scanf a pointer to.." instead of "the
    function returns the address of.." or "we have to send scanf the
    address of.." '' ...

    .... has absolutely nothing to do with lvalues. What part of that do you not
    understand? So relating your second question to the first in this regard,
    is absolutely meaningless. Try and answer this question again, since
    you completely ignored it in your response. I asked you, to what lvalue
    were you referring to?

    I'll make it extremely simple for you.

    First question,
    ``I'm just wondering why people/books/experts say "the function returns a
    pointer to.." or "we have to send scanf a pointer to.." instead of "the
    function returns the address of.." or "we have to send scanf the
    address of.." ''

    Second question,
    ``Isn't the lvalue called a POINTER TO and the (r)value called the
    ADDRESS OF?''

    Where is the lvalue that you are referring to in the first question?
    I see no such lvalue mentioned.
     
    j, Jan 31, 2005
    #15
  16. Pointers are objects
    and the values that they contain are addresses.
    The representation of addresses is implementation dependent.
    They may be [virtual] memory addresses.

    int i = 0;
    int* p = &i;

    p is a pointer to an object of type int.
    &i is the address of an object of type int.


    void f(int* p);
    f(p); // passes a pointer to f(int*)
    f(&i) // passes an address to f(int*)

    But, since p == &i, it might be correct to say either one.
     
    E. Robert Tisdale, Jan 31, 2005
    #16
  17. TTroy

    Big K Guest

    Ok guys, stop clogging up the internet with these posts (the backbone
    routers are sweating).

    As for the argument, I think you(j) totally misunderstood the original
    post. I have no idea how you thought a sentence in the middle of the
    post was unrelated to the subject at hand.

    I was going to respond to the original post, but Chris Torek posted an
    answer 10 times better than mine.
     
    Big K, Jan 31, 2005
    #17
  18. TTroy

    j Guest

    It is simple. What is the lvalue that he is referring to?
     
    j, Jan 31, 2005
    #18
  19. TTroy

    Sniper1 Guest

    How about learning how to snip for crying out loud?
     
    Sniper1, Jan 31, 2005
    #19
  20. TTroy

    Mike Wahler Guest

    A pointer is an object. An address is a value.
    A pointer object can store the value of an address.
    This address value becomes the pointer object's value.
    People will use often 'pointer' and 'address' interchangeably,
    but technically a function would return an 'address
    value', which can be stored in a pointer type object.

    -Mike
     
    Mike Wahler, Jan 31, 2005
    #20
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.