Good Tutorials

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

    #46
    Re: Good Tutorials

    Tristan Miller <psychonaut@not hingisreal.comw rites:
    Greetings.
    >
    In article
    <3f8adc51-f9af-4da2-8580-0be40f99615d@s9 g2000prg.google groups.com>,
    Amkcoder wrote:
    >Every time you declare a pointer space is allocated for it to hold a
    >value
    >
    Oh, really? Perhaps you could explain to us, then, how and where the
    system allocates space for the following pointer declaration?
    >
    extern int *p;
    That is declaring that the variable is external. It is not "declaring a
    variable" in my view. I'm sure that thats probably over simplified and
    breaks something in the standard but there you go.
    >
    Regards,
    Tristan
    --

    Comment

    • Keith Thompson

      #47
      Re: Good Tutorials

      soscpd <soscpd@gmail.c omwrites:
      [...]
      But every time we are discussing something on c.l.c, we must follow
      the standards, thinking, speaking and so on. Well... was my mistake do
      not follow that simple rules. By return, I mean: If you use it, in
      some place where you expect the variable value, you will get the value
      (please... no to initialization, error and stuff. Consider the utopia
      with me, right now. I'm not a C teacher and my goal is not follow the
      standards as standards... they are more general guidelines to me),
      like:
      >
      int *p = malloc(sizeof(i nt));
      p=2;
      I assume you meant "*p = 2;".
      So... p is a pointer to a memory location of int size?
      Right.
      After all... the machine job is to go to that location and "return"
      the value, if I ask for it.
      >
      That's was my return definition in there.
      I'm having trouble understanding what you mean. By "my return
      definition", I *think* you mean your definition of the word "return",
      and I think you're trying to argue that the pointer p can "return" the
      value 2. Is that correct?

      I suggest that greater precision both in your C and in your English
      would serve you well.

      Personally, when talking about C, I use the word "return" only to
      refer to a value returned by a function (using the "return" keyword),
      where as an expression *yields* a value. But ok, if you want to say
      that an expression returns a value, that's not too horribly bad. But
      in your example, exactly what returns what? Are you saying that the
      pointer object p "returns" the value 2? If so, how would you say what
      I express as "the expression ``p'' yields a pointer value of type
      int*"?

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <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"

      Comment

      • Keith Thompson

        #48
        Re: Good Tutorials

        Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
        On 23 Sep, 18:21, Richard<rgr...@ gmail.comwrote:
        [...]
        >This constant desire to confuse people with a "pointer is not an
        >address" is simply ridiculous. It is an "address". You address an object
        >or memory or whatever through it. One representation of that address is
        >as a value which can be displayed as a hexadecimal memory "address".
        >
        this was wrong the first time you said it. It is still wrong.
        [...]

        Um, how is it wrong?

        A pointer is an address; the way the standard defines the terms,
        they're nearly synonymous (though I suspect Richard is using the term
        "address" in some more hardware-specific way). And it's always
        possible to represent a pointer value / address in hexadecimal; even
        if "%p" doesn't do this, you can interpret its representation as an
        array of unsigned char.

        An address is not a number (though it's often implemented that way),
        but Richard didn't make that particular claim here.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <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"

        Comment

        • jameskuyper@verizon.net

          #49
          Re: Good Tutorials

          Richard wrote:
          Tristan Miller <psychonaut@not hingisreal.comw rites:
          >
          Greetings.

          In article
          <3f8adc51-f9af-4da2-8580-0be40f99615d@s9 g2000prg.google groups.com>,
          Amkcoder wrote:
          Every time you declare a pointer space is allocated for it to hold a
          value
          Oh, really? Perhaps you could explain to us, then, how and where the
          system allocates space for the following pointer declaration?

          extern int *p;
          >
          That is declaring that the variable is external. It is not "declaring a
          variable" in my view. I'm sure that thats probably over simplified and
          breaks something in the standard but there you go.
          It doesn't break something, it just doesn't use the jargon correctly.
          The standard doesn't use the term "variable". However, that
          declaration unambiguously declares the identifier 'p', which is the
          name of an object, in exactly the same sense that

          int f(int);

          declares the identifier 'f', which is the name of a function. if you
          accept the definition I'm familiar with (variable = "named object"),
          then this means that the declaration declares a variable named 'p'.

          What neither statement does is define the thing that the identifier
          identifies. If Amkcoder had said "Every time you define a pointer
          variable, space is allocated to store its value", he would have been
          reasonably accurate There's a big difference between declaring an
          identifier and defining the thing that the identifier identifies.

          Comment

          • Richard

            #50
            Re: Good Tutorials

            jameskuyper@ver izon.net writes:
            Richard wrote:
            >Tristan Miller <psychonaut@not hingisreal.comw rites:
            >>
            Greetings.
            >
            In article
            <3f8adc51-f9af-4da2-8580-0be40f99615d@s9 g2000prg.google groups.com>,
            Amkcoder wrote:
            >Every time you declare a pointer space is allocated for it to hold a
            >value
            >
            Oh, really? Perhaps you could explain to us, then, how and where the
            system allocates space for the following pointer declaration?
            >
            extern int *p;
            >>
            >That is declaring that the variable is external. It is not "declaring a
            >variable" in my view. I'm sure that thats probably over simplified and
            >breaks something in the standard but there you go.
            >
            It doesn't break something, it just doesn't use the jargon correctly.
            The standard doesn't use the term "variable". However, that
            declaration unambiguously declares the identifier 'p', which is the
            name of an object, in exactly the same sense that
            >
            int f(int);
            >
            declares the identifier 'f', which is the name of a function. if you
            accept the definition I'm familiar with (variable = "named object"),
            then this means that the declaration declares a variable named 'p'.
            >
            What neither statement does is define the thing that the identifier
            identifies. If Amkcoder had said "Every time you define a pointer
            variable, space is allocated to store its value", he would have been
            reasonably accurate There's a big difference between declaring an
            identifier and defining the thing that the identifier identifies.
            I know. But one does not need to be a genius to know what he meant. or
            one to understand what I said.

            Comment

            • pete

              #51
              Re: Good Tutorials

              Flash Gordon wrote:
              Amkcoder wrote, On 23/09/08 17:50:
              >
              <snip>
              This leads to another mistake in your tutorial. You say...
              >The address of memory allocated by a declared variable may be retrieved
              >with the address of operator for assignment to a pointer, or for
              >later storage.
              >This works on any variable but pointers, if it is a pointer one
              >may retrieve the address it holds by excluding the asterik prefixed
              >to its identifier.
              >
              This is wrong.
              Very wrong.

              To "retrieve the address it holds",
              neither an ampersand nor an asterisk is used.

              The asterisk is used to reference the value of the object
              that the pointer points to.
              The address operator "&" works perfectly well on pointer
              variables, I know because the standard says so and I use it.
              --
              pete

              Comment

              • Keith Thompson

                #52
                Re: Good Tutorials

                pete <pfiland@mindsp ring.comwrites:
                [...]
                To "retrieve the address it holds",
                neither an ampersand nor an asterisk is used.
                >
                The asterisk is used to reference the value of the object
                that the pointer points to.
                [...]

                Or to refer to the object itself; unary * yields an lvalue.

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <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"

                Comment

                • Nick Keighley

                  #53
                  Re: Good Tutorials

                  On 24 Sep, 17:46, Keith Thompson <ks...@mib.orgw rote:
                  Nick Keighley<nick_k eighley_nos...@ hotmail.comwrit es:
                  On 23 Sep, 18:21, Richard<rgr...@ gmail.comwrote:
                  This constant desire to confuse people with a "pointer is not an
                  address" is simply ridiculous. It is an "address". You address an object
                  or memory or whatever through it. One representation of that address is
                  as a value which can be displayed as a hexadecimal memory "address".
                  >
                  this was wrong the first time you said it. It is still wrong.
                  >
                  Um, how is it wrong?
                  >
                  A pointer is an address; the way the standard defines the terms,
                  they're nearly synonymous (though I suspect Richard is using the term
                  "address" in some more hardware-specific way).  And it's always
                  possible to represent a pointer value / address in hexadecimal; even
                  if "%p" doesn't do this, you can interpret its representation as an
                  array of unsigned char.
                  >
                  An address is not a number (though it's often implemented that way),
                  but Richard didn't make that particular claim here.
                  yes. I meant "a pointer is not a number" rather than "a pointer
                  is not an address". I interpreted "it's always possible to represent
                  a pointer value / address in hexadecimal" as "a pointer is a number".


                  --
                  Nick Keighley

                  Comment

                  • Richard

                    #54
                    Re: Good Tutorials

                    Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                    On 24 Sep, 17:46, Keith Thompson <ks...@mib.orgw rote:
                    >Nick Keighley<nick_k eighley_nos...@ hotmail.comwrit es:
                    On 23 Sep, 18:21, Richard<rgr...@ gmail.comwrote:
                    >
                    >This constant desire to confuse people with a "pointer is not an
                    >address" is simply ridiculous. It is an "address". You address an object
                    >or memory or whatever through it. One representation of that address is
                    >as a value which can be displayed as a hexadecimal memory "address".
                    >>
                    this was wrong the first time you said it. It is still wrong.
                    >>
                    >Um, how is it wrong?
                    >>
                    >A pointer is an address; the way the standard defines the terms,
                    >they're nearly synonymous (though I suspect Richard is using the term
                    >"address" in some more hardware-specific way).  And it's always
                    >possible to represent a pointer value / address in hexadecimal; even
                    >if "%p" doesn't do this, you can interpret its representation as an
                    >array of unsigned char.
                    >>
                    >An address is not a number (though it's often implemented that way),
                    >but Richard didn't make that particular claim here.
                    >
                    yes. I meant "a pointer is not a number" rather than "a pointer
                    is not an address". I interpreted "it's always possible to represent
                    a pointer value / address in hexadecimal" as "a pointer is a number".
                    So where was I wrong?

                    And and address on MOST platforms IS represented as a number ....

                    This whole issue is somewhat silly.

                    Comment

                    • Ben Bacarisse

                      #55
                      Re: Good Tutorials

                      Richard<rgrdev@ gmail.comwrites :
                      Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                      >
                      >On 24 Sep, 17:46, Keith Thompson <ks...@mib.orgw rote:
                      >>Nick Keighley<nick_k eighley_nos...@ hotmail.comwrit es:
                      >On 23 Sep, 18:21, Richard<rgr...@ gmail.comwrote:
                      >>
                      >>This constant desire to confuse people with a "pointer is not an
                      >>address" is simply ridiculous. It is an "address". You address an object
                      >>or memory or whatever through it. One representation of that address is
                      >>as a value which can be displayed as a hexadecimal memory "address".
                      >>>
                      >this was wrong the first time you said it. It is still wrong.
                      >>>
                      >>Um, how is it wrong?
                      >>>
                      >>A pointer is an address; the way the standard defines the terms,
                      >>they're nearly synonymous (though I suspect Richard is using the term
                      >>"address" in some more hardware-specific way).  And it's always
                      >>possible to represent a pointer value / address in hexadecimal; even
                      >>if "%p" doesn't do this, you can interpret its representation as an
                      >>array of unsigned char.
                      >>>
                      >>An address is not a number (though it's often implemented that way),
                      >>but Richard didn't make that particular claim here.
                      >>
                      >yes. I meant "a pointer is not a number" rather than "a pointer
                      >is not an address". I interpreted "it's always possible to represent
                      >a pointer value / address in hexadecimal" as "a pointer is a number".
                      >
                      So where was I wrong?
                      Where you claimed that there was a 'constant desire to confuse people
                      with a "pointer is not an address"'. That claim is never made by
                      knowledgeable posters and I have seem Keith Thompson correct it a
                      couple of time when it is made by people who are obviously already
                      confused. Nobody that you would call a "reg" makes it and none of
                      them have a desire to confuse people by introducing such a falsehood.
                      And and address on MOST platforms IS represented as a number ....
                      Stick with that and I doubt there will be much dissent.

                      --
                      Ben.

                      Comment

                      • soscpd

                        #56
                        Re: Good Tutorials

                        Hello Richard, James, List

                        On Sep 24, 7:03 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                        soscpd said:
                        A teacher should never try to tell the whole truth (because there isn't
                        time
                        And, maybe: "..., neither whole truth..." :-)


                        On Sep 24, 7:28 am, James Kuyper <jameskuy...@ve rizon.netwrote:
                        soscpd wrote:
                        Technical jargon serves many purposes, including the ignoble purpose of
                        separating the in-group and the out-group. However, it's main purpose is
                        to clearly communicate complex concepts ...
                        Yes indeed.
                        I suspect that you actually understand the difference those words
                        Yes, I did.
                        describe; I just think you're unclear about the fact that those words
                        describe that difference.
                        Hey... I did understand that too.
                        The difference is that a pointer object is a piece of memory
                        Here is, probably, my real problem. As far as my knowledge can lead
                        me, a pointer is an address to the beginning of a memory location.
                        That, in my words, make the pointer to not be ever a value. Knowing
                        the correct address (same to say - having the correct pointer), I can
                        explore (I know, with undefined consequences) any "in memory" value/
                        object/whatever.

                        Due to optimization, that pointer value might never be stored anywhere -
                        p+3 might be combined with some other operation, as in (p+3)->count.
                        Hey... "anywhere" is one of the powerful stuff about pointers.
                        That C code might be translated into machine code which retrieves the
                        byte address stored in p, and then adds to it, in a single instruction,
                        the combined values of 3*sizeof *p and the offset of the 'count' member
                        within the struct pointed at by p.
                        Ok.
                        The distinction between a pointer object and a pointer value is
                        ....
                        Ok... taking the words object and value, a pointer object is the
                        pointer itself. Pointer value is the (address - beginning of the)
                        memory location who the pointer point's to. You will, then, use the
                        memory contents from pointer address to sizeof pointer type * n (where
                        n should be unsigned int 0). If not... how can a void type ever
                        exists?

                        I mean... the only possible value of a pointer is a memory location,
                        right? The memory content's and how to handle it should be another
                        subject, IMHO.



                        Thanks
                        Rafael

                        Comment

                        • James Kuyper

                          #57
                          Re: Good Tutorials

                          soscpd wrote:
                          Hello Richard, James, List
                          ....
                          >The difference is that a pointer object is a piece of memory
                          >
                          Here is, probably, my real problem. As far as my knowledge can lead
                          me, a pointer is an address to the beginning of a memory location.
                          A pointer value is the memory location itself. A pointer value can be
                          represented in a pointer object by the machine address of that location.
                          That, in my words, make the pointer to not be ever a value.
                          I don't understand why you would say that. The value of an object is,
                          always, an abstract thing, like the number 3. The contents of the
                          object, on the other hand, are concrete things like bits which are
                          either turned on or off, in a pattern which represents the value. This
                          is precisely the same relationship that exists between the value of a
                          pointer and the bit pattern that ist stored in a pointer object.
                          ... Knowing
                          the correct address (same to say - having the correct pointer), I can
                          explore (I know, with undefined consequences) any "in memory" value/
                          object/whatever.
                          >
                          >
                          >Due to optimization, that pointer value might never be stored anywhere -
                          >p+3 might be combined with some other operation, as in (p+3)->count.
                          >
                          Hey... "anywhere" is one of the powerful stuff about pointers.
                          Yes, and despite the power of pointers, no pointer can point at the
                          location where the value of p+3 is stored, during the evaluation of
                          (p+3)->count.

                          Comment

                          • Bartc

                            #58
                            Re: Good Tutorials


                            "soscpd" <soscpd@gmail.c omwrote in message
                            news:ac899717-c1ae-4d4d-93c0-f4a759c423ed@8g 2000hse.googleg roups.com...

                            I mean... the only possible value of a pointer is a memory location,
                            right? The memory content's and how to handle it should be another
                            subject, IMHO.
                            A pointer can have a whole bunch of values that are not memory locations.

                            Maybe the memory simply doesn't exist. Or is outside an allowed range. Or
                            the value might be valid for one type of target but not for another (for
                            example a pointer to a word might require an 'even' pointer value, or the
                            targets exist in different memory spaces).

                            And sometimes, you might have different pointer values addressing the same
                            memory location.

                            --
                            Bartc

                            Comment

                            • soscpd

                              #59
                              Re: Good Tutorials

                              Hello James, Bartc, List

                              On Sep 25, 8:45 am, James Kuyper <jameskuy...@ve rizon.netwrote:
                              A pointer value is the memory location itself.
                              My question is - isn't the pointer the memory address? Just the memory
                              address, with nothing else?
                              That, in my words, make the pointer to not be ever a value.
                              I don't understand why you would say that. The value of an object is,
                              always, an abstract thing, like the number 3.
                              The pointer value or object will never be 3 (sorry about "will not be
                              ever a value". What I mean is - the pointer value will never be 3, in
                              that case). It will be the address of a memory location. The memory
                              location will have the desired value (well... that depends of what you
                              are looking for).


                              On Sep 25, 8:57 am, "Bartc" <b...@freeuk.co mwrote:
                              A pointer can have a whole bunch of values that are not memory locations.
                              Yes... that is exactly the thing I can't figure. Isn't the point a
                              address to the value? Or is the pointer the value itself?

                              Maybe the memory simply doesn't exist. Or is outside an allowed range.
                              Please, define allowed. You mean, allowed for defined behavior?

                              the value might be valid for one type of target but not for another
                              Agreed. But that is not part of the (pointer) subject, IMHO.


                              Why we need to mix the pointer with the memory contents the pointer
                              point's to? There are too many possible values. Maybe understanding
                              pointers just as the address to memory locations will make our lifes
                              easy.

                              Through pointers, we can:
                              Reserve/Release some reserved memory(malloc & cia);
                              Point to some memory location (doesn't matter what is inside, except
                              if yu will use it);
                              Get whatever from reserved space (so, read memory from pointer to
                              sizeof(data));
                              Assign whatever to reserved space (or not reserved space - UB);
                              ....

                              I just don't know if it is true (by the book. Using it just like that
                              works very fine... so far :-).

                              Regards
                              Rafael

                              Comment

                              • Richard Bos

                                #60
                                Re: Good Tutorials

                                soscpd <soscpd@gmail.c omwrote:
                                On Sep 25, 8:45 am, James Kuyper <jameskuy...@ve rizon.netwrote:
                                A pointer value is the memory location itself.
                                >
                                My question is - isn't the pointer the memory address? Just the memory
                                address, with nothing else?
                                Not necessarily. First, "address" can mean a lot more than just "index
                                into one giant pool of memory". And then a pointer is allowed to hold
                                more information than just the address itself. It can hold the size of
                                the memory block, to detect memory overflow, in debugging
                                implementations . Or it can hold the type of the object pointed at. That
                                needs a bit of fiddling with void *s, but it's possible.

                                Richard

                                Comment

                                Working...