basic pointer code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pauldepstein@att.net

    #1

    basic pointer code

    I don't quite understand some code that looks like this

    int zeronumber = 0;
    SomeMember.Some Function(&zeron umber);

    I'm almost sure that SomeFunction is a function defined on pointer-to-
    int, and is here being applied to the null pointer. But, if I'm
    right, it would seem that SomeFunction would be applied to
    (zeronumber) rather than (&zeronumber) . &zeronumber would seem to
    mean "the address of a null pointer" which doesn't make sense. I'm
    basically confused by the ampersand in front of zeronumber.

    Thank you,

    Paul Epstein

  • terminator

    #2
    Re: basic pointer code

    On Oct 28, 11:11 am, pauldepst...@at t.net wrote:
    I don't quite understand some code that looks like this
    >
    int zeronumber = 0;
    SomeMember.Some Function(&zeron umber);
    >
    I'm almost sure that SomeFunction is a function defined on pointer-to-
    int, and is here being applied to the null pointer. But, if I'm
    right, it would seem that SomeFunction would be applied to
    (zeronumber) rather than (&zeronumber) . &zeronumber would seem to
    mean "the address of a null pointer" which doesn't make sense. I'm
    basically confused by the ampersand in front of zeronumber.
    >
    the address of an object is distinct from its value.'zeronumb er' is
    not a pointer ,it is an integer initialized to zero.'&zeronumb er' is a
    pointer addressing the location of an integer which is named as
    'zeronumber' ,since it is the address of a named object it cn not be
    null.Here is the definition of a pointer initailized to null:

    int * intptr=0;

    cheers,
    FM.


    Comment

    • pauldepstein@att.net

      #3
      Re: basic pointer code

      On Oct 28, 4:49 pm, terminator <farid.mehr...@ gmail.comwrote:
      On Oct 28, 11:11 am, pauldepst...@at t.net wrote:
      >
      I don't quite understand some code that looks like this
      >
      int zeronumber = 0;
      SomeMember.Some Function(&zeron umber);
      >
      I'm almost sure that SomeFunction is a function defined on pointer-to-
      int, and is here being applied to the null pointer. But, if I'm
      right, it would seem that SomeFunction would be applied to
      (zeronumber) rather than (&zeronumber) . &zeronumber would seem to
      mean "the address of a null pointer" which doesn't make sense. I'm
      basically confused by the ampersand in front of zeronumber.
      >
      the address of an object is distinct from its value.'zeronumb er' is
      not a pointer ,it is an integer initialized to zero.'&zeronumb er' is a
      pointer addressing the location of an integer which is named as
      'zeronumber' ,since it is the address of a named object it cn not be
      null.Here is the definition of a pointer initailized to null:
      >
      int * intptr=0;
      >
      cheers,
      FM.
      Thanks, Terminator. I'm fairly sure the author wants to apply a
      function to the null pointer.
      >From what you're saying, I've discovered a bug!
      Paul Epstein

      Comment

      • werasm

        #4
        Re: basic pointer code

        On Oct 28, 10:16 am, pauldepst...@at t.net wrote:
        Thanks, Terminator. I'm fairly sure the author wants to apply a
        function to the null pointer.
        I see no NULL pointer in the code presented, I only
        see an integer that is initialized to the value zero.

        The pointer passed to the function is perfectly valid
        and not zero because the value of the pointer and the
        value of the integer are two distinct things. Why the
        author of the function chose a pointer as argument
        is a different matter on which I won't even begin
        to speculate.

        Regards,

        Werner


        Comment

        • pauldepstein@att.net

          #5
          Re: basic pointer code

          On Oct 29, 4:02 am, werasm <wer...@gmail.c omwrote:
          On Oct 28, 10:16 am, pauldepst...@at t.net wrote:
          >
          Thanks, Terminator. I'm fairly sure the author wants to apply a
          function to the null pointer.
          >
          I see no NULL pointer in the code presented, I only
          see an integer that is initialized to the value zero.
          >
          The pointer passed to the function is perfectly valid
          and not zero because the value of the pointer and the
          value of the integer are two distinct things. Why the
          author of the function chose a pointer as argument
          is a different matter on which I won't even begin
          to speculate.
          >
          Regards,
          >
          Werner
          The code is actually fine, and I jumped to conclusions in suspecting a
          mistake. If you look at the freeware of xlw, you will see that there
          are functions applied to uninitialised variables, via pointers to
          those variables. I found that confusing at first. The author of the
          code was writing functions that work with xlw. xlw uses pointers to
          the addresses of uninitialised ints and doubles. The author could
          have said int x; and then used &x.

          Paul Epstein

          Comment

          Working...