difference between address and pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • somenath

    difference between address and pointer

    Hi All.

    I would like to know the following information.

    1)Is there any difference between the address and integer ?

    For example suppose int x = 500;
    And int y =10;
    Suppose address of y is also 500;
    My doubt is there any difference between the properties of value of x
    and address of y which is 500.

    Regards,
    Somenath
    Int x =500;

  • Chris Dollin

    #2
    Re: difference between address and pointer

    somenath wrote:
    I would like to know the following information.
    >
    1)Is there any difference between the address and integer ?
    Addresses (and pointers) are different from integers.
    For example suppose int x = 500;
    And int y =10;
    Suppose address of y is also 500;
    It isn't. 500 is an integer; the address of y is a pointer. They
    are two distinguishable types /even if/ the underlying machine uses
    integer-like bit-patterns as pointers and integer arithmetic to
    do address calculations.
    My doubt is there any difference between the properties of value of x
    and address of y which is 500.
    Yes. For example, it's legal to multiply an integer by another integer,
    but not to multiply an address by an integer. Integer values can
    be assigned to floating variables; addresses cannot. You cannot
    dereference an integer. Etc.

    --
    Chris "almost but not quite completely different" Dollin

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN

    Comment

    • Mark Bluemel

      #3
      Re: difference between address and pointer

      somenath wrote:
      Hi All.
      >
      I would like to know the following information.
      >
      1)Is there any difference between the address and integer ?
      >
      For example suppose int x = 500;
      And int y =10;
      Suppose address of y is also 500;
      My doubt is there any difference between the properties of value of x
      and address of y which is 500.
      This question is regularly thrashed over in the group. A little scanning
      in Google Groups would probably find the most recent discussion...

      Two points for now:-
      1) The format of a pointer is not defined by the C standard
      2) Not all systems have "flat" address spaces, so the idea that an
      address is an integer is not portable.

      Comment

      • Eric Sosman

        #4
        Re: difference between address and pointer

        somenath wrote On 08/09/07 10:12,:
        Hi All.
        >
        I would like to know the following information.
        >
        1)Is there any difference between the address and integer ?
        >
        For example suppose int x = 500;
        And int y =10;
        Suppose address of y is also 500;
        My doubt is there any difference between the properties of value of x
        and address of y which is 500.
        Other respondents have explained that a pointer is
        not an integer, by showing that an address is not an
        integer. But the difference goes even deeper: a pointer
        is not just an address. Contemplate this code fragment
        for a while, and you'll understand why a pointer is more
        than an address:

        union { double d; int i; } u;
        double *dp = &u.d;
        int *ip = &u.i;

        In this code, the two pointers dp and ip point to the
        same memory location. Nonetheless, they are different.
        What makes them different?

        --
        Eric.Sosman@sun .com

        Comment

        • CBFalconer

          #5
          Re: difference between address and pointer

          somenath wrote:
          >
          I would like to know the following information.
          >
          1)Is there any difference between the address and integer ?
          >
          For example suppose int x = 500;
          And int y =10;
          Suppose address of y is also 500;
          My doubt is there any difference between the properties of value of x
          and address of y which is 500.
          Yes. You haven't completed the description of y, which also needs
          to specify such things as memory block, whether or not actually in
          memory (may be on disk, and swapped out, for example), etc. etc.
          POINTERS ARE NOT INTEGERS.

          --
          Chuck F (cbfalconer at maineline dot net)
          Available for consulting/temporary embedded and systems.
          <http://cbfalconer.home .att.net>


          --
          Posted via a free Usenet account from http://www.teranews.com

          Comment

          • Malcolm McLean

            #6
            Re: difference between address and pointer


            "somenath" <somenathpal@gm ail.comwrote in message
            news:1186668727 .119010.230300@ q3g2000prf.goog legroups.com...
            Hi All.
            >
            I would like to know the following information.
            >
            1)Is there any difference between the address and integer ?
            >
            For example suppose int x = 500;
            And int y =10;
            Suppose address of y is also 500;
            My doubt is there any difference between the properties of value of x
            and address of y which is 500.
            >
            On the notional van Neumann machine pointers are integers that index the
            memory space. Most computers do work like that. But not all. Some processors
            have segmented architectures. Some compilers carry around extra information
            with pointers to help catch buffer overruns. Siome implement 8 bit bytes on
            top of processors which are inherently 32 bit.

            So it is not normally helpful to think of a pointer as an integer.

            --
            Free games and programming goodies.



            Comment

            • Keith Thompson

              #7
              Re: difference between address and pointer

              Eric Sosman <Eric.Sosman@su n.comwrites:
              [...]
              Other respondents have explained that a pointer is
              not an integer, by showing that an address is not an
              integer. But the difference goes even deeper: a pointer
              is not just an address.
              [...]

              Except that the standard tends to use the terms "pointer" and
              "address" more or less interchangeably . For example, the unary '&'
              operator yields the *address* of its operand.

              The term "address" is also commonly used to refer to a raw machine
              address (the difference is whether it simply refers to a location in
              memory, or also has type information associated with it).

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              • Joe Wright

                #8
                Re: difference between address and pointer

                Eric Sosman wrote:
                somenath wrote On 08/09/07 10:12,:
                >Hi All.
                >>
                >I would like to know the following information.
                >>
                >1)Is there any difference between the address and integer ?
                >>
                >For example suppose int x = 500;
                >And int y =10;
                >Suppose address of y is also 500;
                >My doubt is there any difference between the properties of value of x
                >and address of y which is 500.
                >
                Other respondents have explained that a pointer is
                not an integer, by showing that an address is not an
                integer. But the difference goes even deeper: a pointer
                is not just an address. Contemplate this code fragment
                for a while, and you'll understand why a pointer is more
                than an address:
                >
                union { double d; int i; } u;
                double *dp = &u.d;
                int *ip = &u.i;
                >
                In this code, the two pointers dp and ip point to the
                same memory location. Nonetheless, they are different.
                What makes them different?
                >
                They have different type. They have identical value. They have identical
                size (4). They cannot be distinguished from one another except by the
                compiler. Why do you think they are different?

                --
                Joe Wright
                "Everything should be made as simple as possible, but not simpler."
                --- Albert Einstein ---

                Comment

                • Keith Thompson

                  #9
                  Re: difference between address and pointer

                  Joe Wright <joewwright@com cast.netwrites:
                  Eric Sosman wrote:
                  [...]
                  > Other respondents have explained that a pointer is
                  >not an integer, by showing that an address is not an
                  >integer. But the difference goes even deeper: a pointer
                  >is not just an address. Contemplate this code fragment
                  >for a while, and you'll understand why a pointer is more
                  >than an address:
                  > union { double d; int i; } u;
                  > double *dp = &u.d;
                  > int *ip = &u.i;
                  >In this code, the two pointers dp and ip point to the
                  >same memory location. Nonetheless, they are different.
                  >What makes them different?
                  >>
                  They have different type. They have identical value. They have
                  identical size (4). They cannot be distinguished from one another
                  except by the compiler. Why do you think they are different?
                  You said it yourself: they have different type.

                  Furthermore, how do you know they have the same size, or that their
                  size is 4 bytes? I work on systems where they'd both have a size of 8
                  bytes, and it's entirely possible for their sizes to differ.

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                  "We must do something. This is something. Therefore, we must do this."
                  -- Antony Jay and Jonathan Lynn, "Yes Minister"

                  Comment

                  • Eric Sosman

                    #10
                    Re: difference between address and pointer

                    Joe Wright wrote On 08/09/07 18:01,:
                    Eric Sosman wrote:
                    >
                    >>somenath wrote On 08/09/07 10:12,:
                    >>
                    >>>Hi All.
                    >>>
                    >>>I would like to know the following information.
                    >>>
                    >>>1)Is there any difference between the address and integer ?
                    >>>
                    >>>For example suppose int x = 500;
                    >>>And int y =10;
                    >>>Suppose address of y is also 500;
                    >>>My doubt is there any difference between the properties of value of x
                    >>>and address of y which is 500.
                    >>
                    > Other respondents have explained that a pointer is
                    >>not an integer, by showing that an address is not an
                    >>integer. But the difference goes even deeper: a pointer
                    >>is not just an address. Contemplate this code fragment
                    >>for a while, and you'll understand why a pointer is more
                    >>than an address:
                    >>
                    >> union { double d; int i; } u;
                    >> double *dp = &u.d;
                    >> int *ip = &u.i;
                    >>
                    >>In this code, the two pointers dp and ip point to the
                    >>same memory location. Nonetheless, they are different.
                    >>What makes them different?
                    >>
                    >
                    They have different type. They have identical value. They have identical
                    size (4). They cannot be distinguished from one another except by the
                    compiler. Why do you think they are different?
                    Because `array[*ip]' might work (given a suitable
                    value in `u.i') while `array[*dp]' won't even compile.

                    Because `ip = dp' won't even compile.

                    Because `sizeof *ip != sizeof *dp' (probably).

                    Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
                    probably invokes undefined behavior.

                    Because `if ((*dp = DBL_MIN))' branches oppositely
                    to `if ((*ip = DBL_MIN))'.

                    Because `printf ("%f\n", *dp)' works (with a suitable
                    value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
                    behavior, always.

                    Because we've moved beyond B.

                    --
                    Eric.Sosman@sun .com


                    Comment

                    • Joe Wright

                      #11
                      Re: difference between address and pointer

                      Eric Sosman wrote:
                      Joe Wright wrote On 08/09/07 18:01,:
                      >Eric Sosman wrote:
                      >>
                      >>somenath wrote On 08/09/07 10:12,:
                      >>>
                      >>>Hi All.
                      >>>>
                      >>>I would like to know the following information.
                      >>>>
                      >>>1)Is there any difference between the address and integer ?
                      >>>>
                      >>>For example suppose int x = 500;
                      >>>And int y =10;
                      >>>Suppose address of y is also 500;
                      >>>My doubt is there any difference between the properties of value of x
                      >>>and address of y which is 500.
                      >> Other respondents have explained that a pointer is
                      >>not an integer, by showing that an address is not an
                      >>integer. But the difference goes even deeper: a pointer
                      >>is not just an address. Contemplate this code fragment
                      >>for a while, and you'll understand why a pointer is more
                      >>than an address:
                      >>>
                      >> union { double d; int i; } u;
                      >> double *dp = &u.d;
                      >> int *ip = &u.i;
                      >>>
                      >>In this code, the two pointers dp and ip point to the
                      >>same memory location. Nonetheless, they are different.
                      >>What makes them different?
                      >>>
                      >They have different type. They have identical value. They have identical
                      >size (4). They cannot be distinguished from one another except by the
                      >compiler. Why do you think they are different?
                      >
                      Because `array[*ip]' might work (given a suitable
                      value in `u.i') while `array[*dp]' won't even compile.
                      >
                      Because `ip = dp' won't even compile.
                      >
                      Because `sizeof *ip != sizeof *dp' (probably).
                      >
                      Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
                      probably invokes undefined behavior.
                      >
                      Because `if ((*dp = DBL_MIN))' branches oppositely
                      to `if ((*ip = DBL_MIN))'.
                      >
                      Because `printf ("%f\n", *dp)' works (with a suitable
                      value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
                      behavior, always.
                      >
                      Because we've moved beyond B.
                      >
                      Perhaps I was unclear. Consider please..

                      void *y, *z;
                      y = &u.d;
                      z = &u.i;

                      Now how shall we differentiate between y and z?

                      --
                      Joe Wright
                      "Everything should be made as simple as possible, but not simpler."
                      --- Albert Einstein ---

                      Comment

                      • Eric Sosman

                        #12
                        Re: difference between address and pointer

                        Joe Wright wrote:
                        Eric Sosman wrote:
                        >Joe Wright wrote On 08/09/07 18:01,:
                        >>Eric Sosman wrote:
                        >>>
                        >>>somenath wrote On 08/09/07 10:12,:
                        >>>>
                        >>>>Hi All.
                        >>>>>
                        >>>>I would like to know the following information.
                        >>>>>
                        >>>>1)Is there any difference between the address and integer ?
                        >>>>>
                        >>>>For example suppose int x = 500;
                        >>>>And int y =10;
                        >>>>Suppose address of y is also 500;
                        >>>>My doubt is there any difference between the properties of value of x
                        >>>>and address of y which is 500.
                        >>> Other respondents have explained that a pointer is
                        >>>not an integer, by showing that an address is not an
                        >>>integer. But the difference goes even deeper: a pointer
                        >>>is not just an address. Contemplate this code fragment
                        >>>for a while, and you'll understand why a pointer is more
                        >>>than an address:
                        >>>>
                        >>> union { double d; int i; } u;
                        >>> double *dp = &u.d;
                        >>> int *ip = &u.i;
                        >>>>
                        >>>In this code, the two pointers dp and ip point to the
                        >>>same memory location. Nonetheless, they are different.
                        >>>What makes them different?
                        >>>>
                        >>They have different type. They have identical value. They have
                        >>identical size (4). They cannot be distinguished from one another
                        >>except by the compiler. Why do you think they are different?
                        >>
                        > Because `array[*ip]' might work (given a suitable
                        >value in `u.i') while `array[*dp]' won't even compile.
                        >>
                        > Because `ip = dp' won't even compile.
                        >>
                        > Because `sizeof *ip != sizeof *dp' (probably).
                        >>
                        > Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
                        >probably invokes undefined behavior.
                        >>
                        > Because `if ((*dp = DBL_MIN))' branches oppositely
                        >to `if ((*ip = DBL_MIN))'.
                        >>
                        > Because `printf ("%f\n", *dp)' works (with a suitable
                        >value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
                        >behavior, always.
                        >>
                        > Because we've moved beyond B.
                        >>
                        Perhaps I was unclear. Consider please..
                        >
                        void *y, *z;
                        y = &u.d;
                        z = &u.i;
                        >
                        Now how shall we differentiate between y and z?
                        They are the same. So are `&u.i' and `(int*)&u'.
                        But `y' and `z' are different from both `dp' and `ip'.

                        --
                        Eric Sosman
                        esosman@ieee-dot-org.invalid

                        Comment

                        • CBFalconer

                          #13
                          Re: difference between address and pointer

                          Joe Wright wrote:
                          Eric Sosman wrote:
                          >
                          .... snip ...
                          >>
                          > union { double d; int i; } u;
                          > double *dp = &u.d;
                          > int *ip = &u.i;
                          >>
                          >In this code, the two pointers dp and ip point to the
                          >same memory location. Nonetheless, they are different.
                          >What makes them different?
                          >
                          They have different type. They have identical value. They have
                          identical size (4). They cannot be distinguished from one another
                          except by the compiler. Why do you think they are different?
                          And what gives you the right to make those statements? The
                          addresses may specify all sorts of added information, such as
                          memory bank, disk drive (for cached), type of data referenced,
                          etc. You don't know how the system organizer has arranged all
                          that.

                          --
                          Chuck F (cbfalconer at maineline dot net)
                          Available for consulting/temporary embedded and systems.
                          <http://cbfalconer.home .att.net>



                          --
                          Posted via a free Usenet account from http://www.teranews.com

                          Comment

                          • CBFalconer

                            #14
                            Re: difference between address and pointer

                            Keith Thompson wrote:
                            Eric Sosman <Eric.Sosman@su n.comwrites:
                            [...]
                            > Other respondents have explained that a pointer is
                            >not an integer, by showing that an address is not an
                            >integer. But the difference goes even deeper: a pointer
                            >is not just an address.
                            [...]
                            >
                            Except that the standard tends to use the terms "pointer" and
                            "address" more or less interchangeably . For example, the unary '&'
                            operator yields the *address* of its operand.
                            >
                            The term "address" is also commonly used to refer to a raw machine
                            address (the difference is whether it simply refers to a location in
                            memory, or also has type information associated with it).
                            Wrong nomenclature IMO. An address is not necessarily an integer.

                            --
                            Chuck F (cbfalconer at maineline dot net)
                            Available for consulting/temporary embedded and systems.
                            <http://cbfalconer.home .att.net>



                            --
                            Posted via a free Usenet account from http://www.teranews.com

                            Comment

                            • Keith Thompson

                              #15
                              Re: difference between address and pointer

                              CBFalconer <cbfalconer@yah oo.comwrites:
                              Keith Thompson wrote:
                              >Eric Sosman <Eric.Sosman@su n.comwrites:
                              >[...]
                              >> Other respondents have explained that a pointer is
                              >>not an integer, by showing that an address is not an
                              >>integer. But the difference goes even deeper: a pointer
                              >>is not just an address.
                              >[...]
                              >>
                              >Except that the standard tends to use the terms "pointer" and
                              >"address" more or less interchangeably . For example, the unary '&'
                              >operator yields the *address* of its operand.
                              >>
                              >The term "address" is also commonly used to refer to a raw machine
                              >address (the difference is whether it simply refers to a location in
                              >memory, or also has type information associated with it).
                              >
                              Wrong nomenclature IMO. An address is not necessarily an integer.
                              Um, where did I mention integers? What I'm calling a "raw machine
                              address" refers to a location in memory. Something integer-like is a
                              common way to implement that, but it's not the only way (except that
                              it's almost certainly made of bits).

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                              "We must do something. This is something. Therefore, we must do this."
                              -- Antony Jay and Jonathan Lynn, "Yes Minister"

                              Comment

                              Working...