Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I was going to write an article about how pointers aren't confusing

I was going to write an article about how pointers aren't confusing

Scheduled Pinned Locked Moved The Lounge
json
54 Posts 26 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H honey the codewitch

    But they're so cute and cuddly. Especially my precious little void*. Who's a good little typeless pointer? YOU ARE!

    Real programmers use butterflies

    C Offline
    C Offline
    CPallini
    wrote on last edited by
    #32

    Quote:

    Especially my precious little void*

    No, that's the Mother Of All The Evil, and your really don't need it in C++.

    "In testa che avete, Signor di Ceprano?" -- Rigoletto

    1 Reply Last reply
    0
    • M Mike Hankey

      Pointers are powerful and easy to use can lead to disaster when not used correctly, as can be seen when trying to debug a pointer problem.

      I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

      U Offline
      U Offline
      User 13269747
      wrote on last edited by
      #33

      Quote:

      Pointers are powerful and easy to use can lead to disaster when not used correctly, as can be seen when trying to debug a pointer problem.

      Anyone trying to debug pointer problems without using valgrind is probably a masochist.

      M 1 Reply Last reply
      0
      • U User 13269747

        Quote:

        Pointers are powerful and easy to use can lead to disaster when not used correctly, as can be seen when trying to debug a pointer problem.

        Anyone trying to debug pointer problems without using valgrind is probably a masochist.

        M Offline
        M Offline
        Mike Hankey
        wrote on last edited by
        #34

        Had never heard of Valgrind.

        I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

        1 Reply Last reply
        0
        • K Kris Lantz

          My confusion with pointers started very early this morning, since I read the subject as, 'printers aren't confusing.' Time for coffee...

          B Offline
          B Offline
          BryanFazekas
          wrote on last edited by
          #35

          Kris Lantz wrote:

          Time for coffee...

          Why did you do that? The only thing you should do before drinking coffee is making coffee. Any other action is futile, except you won't be assimilated. :laugh:

          K R 2 Replies Last reply
          0
          • M Maximilien

            They're not confusing at all. ( I removed the link ) use the wikipedia instead : [Pointer (dog breed) - Wikipedia](https://en.wikipedia.org/wiki/Pointer\_(dog\_breed))

            I'd rather be phishing!

            W Offline
            W Offline
            W Balboos GHB
            wrote on last edited by
            #36

            I thought about that pointer, yesterday, but thought it would destroy the tattered remains of my reputation. Perhaps that is why you can use a pointer to fetch data.

            Ravings en masse^

            "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

            "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

            1 Reply Last reply
            0
            • B BryanFazekas

              Kris Lantz wrote:

              Time for coffee...

              Why did you do that? The only thing you should do before drinking coffee is making coffee. Any other action is futile, except you won't be assimilated. :laugh:

              K Offline
              K Offline
              Kris Lantz
              wrote on last edited by
              #37

              On the weekends, coffee enjoyment is top of the list. The weekdays are a bit more chaotic, and coffee may not be had until about a half hour after getting to work. :^)

              B 1 Reply Last reply
              0
              • M Maximilien

                weird, it passed out over zealous web nanny on my office computer. I removed the link and put the wikipedia link instead. :thumbsup:

                I'd rather be phishing!

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #38

                I suppose it was a google ad or similar... they don't necessarily have to be the same for you as for me or when you took the link as to when I visited the site.

                M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                1 Reply Last reply
                0
                • H honey the codewitch

                  Until I realized in the process of trying to explain them that they probably are. Just because I find something intuitive doesn't mean I can make it intuitive to others. :doh: The secret with pointers is to enjoy the freedom they bring you rather than fearing the danger they present. Aside from that, the rest is details.

                  Real programmers use butterflies

                  S Offline
                  S Offline
                  sam silvercreek
                  wrote on last edited by
                  #39

                  I remember learning pointers being a real "light bulb" type of learning experience for me. I felt like I was banging my head against a wall trying to figure them out, then with a single revelation, they suddenly made complete sense to me. I've never been able to figure out what caused that revelation.

                  H 1 Reply Last reply
                  0
                  • S sam silvercreek

                    I remember learning pointers being a real "light bulb" type of learning experience for me. I felt like I was banging my head against a wall trying to figure them out, then with a single revelation, they suddenly made complete sense to me. I've never been able to figure out what caused that revelation.

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #40

                    I've had several of those epiphanies in development over the years. Like when I finally understood COM on its terms (a binary vtbl based contract) I really enjoy them. I can't remember if pointers was one because it was so long ago.

                    Real programmers use butterflies

                    S 1 Reply Last reply
                    0
                    • K Kris Lantz

                      My confusion with pointers started very early this morning, since I read the subject as, 'printers aren't confusing.' Time for coffee...

                      E Offline
                      E Offline
                      etkid84
                      wrote on last edited by
                      #41

                      Funny you should mention printers. Getting a printer fixed at a large corporation takes an army of people and a week of emails. Perhaps there is a Dilbert comic strip about it. :java:

                      ~d~

                      1 Reply Last reply
                      0
                      • H honey the codewitch

                        I've had several of those epiphanies in development over the years. Like when I finally understood COM on its terms (a binary vtbl based contract) I really enjoy them. I can't remember if pointers was one because it was so long ago.

                        Real programmers use butterflies

                        S Offline
                        S Offline
                        sam silvercreek
                        wrote on last edited by
                        #42

                        I know what you mean, but my "pointer epiphany" was memorable enough to still be clear to me more than 30 years later... now if I could just remember where I put my glasses.

                        1 Reply Last reply
                        0
                        • B BryanFazekas

                          Kris Lantz wrote:

                          Time for coffee...

                          Why did you do that? The only thing you should do before drinking coffee is making coffee. Any other action is futile, except you won't be assimilated. :laugh:

                          R Offline
                          R Offline
                          richwfowler
                          wrote on last edited by
                          #43

                          Even better -- visit your favorite coffee shop. :-)

                          1 Reply Last reply
                          0
                          • K Kris Lantz

                            On the weekends, coffee enjoyment is top of the list. The weekdays are a bit more chaotic, and coffee may not be had until about a half hour after getting to work. :^)

                            B Offline
                            B Offline
                            BryanFazekas
                            wrote on last edited by
                            #44

                            Kris Lantz wrote:

                            The weekdays are a bit more chaotic, and coffee may not be had until about a half hour after getting to work

                            Make coffee at home and bring a travel mug? All jokes aside, sipping my coffee while reading morning emails helps me settle my mind and prepare for the work day. For me there is a settling effect in sipping coffee, even during an ugly commute. I normally work early hours, so the commute isn't as ugly in the AM as the PM, and the folks in the office at my arrival time are doing the same as me, so there is not usually immediate chaos. [Anyone who arrives to immediate chaos appreciates this.] However -- these days, going to work consists of getting up, starting a pot of coffee, and then logging in. My commute is 35 steps instead of 34 miles. I really appreciate WFH!!!

                            1 Reply Last reply
                            0
                            • H honey the codewitch

                              Until I realized in the process of trying to explain them that they probably are. Just because I find something intuitive doesn't mean I can make it intuitive to others. :doh: The secret with pointers is to enjoy the freedom they bring you rather than fearing the danger they present. Aside from that, the rest is details.

                              Real programmers use butterflies

                              M Offline
                              M Offline
                              Martin ISDN
                              wrote on last edited by
                              #45

                              the C abstract machine there is no problem with pointers if you look straight at them. the problem is when somebody tries to wrap them in some obscured "politically correct" story that doesn't hurt a chipmunk if you step on it. i know this line is confusing, but Pascal was my first programing language and when the time came to grow up and use pointers normally i reached for a Pascal programming book... well, that book in it's chapter of pointers had everything else, about lists, about binary trees... but i could not tell what pointers are. i mean, the person who wrote that book constantly repeated how pointers are really useful although you should avoid to use them as much as possible... he doesn't know about pointers. then i read a chapter about pointers from a C tutorial and everything became crystal clear. there was i happy and using pointers in Pascal. the same thing was with win32 programming. you can not learn it from a Delphi book, you need a C book for that. but you can sure as hell do that in Pascal as good (or better) as in C if you learn the right way. pointers are a fundamental thing. the 8086 processor has a few general purpose registers and about the same number of Index registers. out of this bunch SI and DI are your pointers. and i bet you will understand pointers even better if you learn assembly than C, but C is good enough.

                              H 1 Reply Last reply
                              0
                              • M Martin ISDN

                                the C abstract machine there is no problem with pointers if you look straight at them. the problem is when somebody tries to wrap them in some obscured "politically correct" story that doesn't hurt a chipmunk if you step on it. i know this line is confusing, but Pascal was my first programing language and when the time came to grow up and use pointers normally i reached for a Pascal programming book... well, that book in it's chapter of pointers had everything else, about lists, about binary trees... but i could not tell what pointers are. i mean, the person who wrote that book constantly repeated how pointers are really useful although you should avoid to use them as much as possible... he doesn't know about pointers. then i read a chapter about pointers from a C tutorial and everything became crystal clear. there was i happy and using pointers in Pascal. the same thing was with win32 programming. you can not learn it from a Delphi book, you need a C book for that. but you can sure as hell do that in Pascal as good (or better) as in C if you learn the right way. pointers are a fundamental thing. the 8086 processor has a few general purpose registers and about the same number of Index registers. out of this bunch SI and DI are your pointers. and i bet you will understand pointers even better if you learn assembly than C, but C is good enough.

                                H Offline
                                H Offline
                                honey the codewitch
                                wrote on last edited by
                                #46

                                I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)

                                Real programmers use butterflies

                                M 2 Replies Last reply
                                0
                                • H honey the codewitch

                                  I think that's a common trap. It doesn't help that misusing them causes faults because I think that makes them intimidating but all a fault is is an unhandled exception. Fear is a huge stumbling block to growth. It doesn't help that I've seen lots of articles (not necessarily here) rag on pointers and state that they're scary in so many words, probably from authors that never got comfortable with them themselves. A lot of times it's no different than accessing an array.

                                  Real programmers use butterflies

                                  M Offline
                                  M Offline
                                  Martin ISDN
                                  wrote on last edited by
                                  #47

                                  > probably from authors that never got comfortable with them themselves. or maybe got paid to support some language that is safe (secure). security or the opposite of it, fear, sells a lot in modern times. i don't know what is it these days, but everyone is trying to jump on you with a zealot yelling that you are doing something wrong. that you're incompetent. loser. that they are going to open your eyes with this new way, new programming language, new framework... ok, i get that. these are lamer times. instead of friendship there is mostly ridicule, which makes everybody look bad in the eye of the beholder. although new or old things have interesting ideas, nothing is black and white. "if somebody is selling you a technique in convincing you that there is something that you should do, they're focusing on the benefits and they are either gonna be downplaying the drawbacks or they'll be ignoring them completely" - Jonathan Blow on Software Quality at the CSUA GM2

                                  1 Reply Last reply
                                  0
                                  • H honey the codewitch

                                    I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)

                                    Real programmers use butterflies

                                    M Offline
                                    M Offline
                                    Martin ISDN
                                    wrote on last edited by
                                    #48

                                    yeah, i was on the 6502 too. the most close to pointers out of the top of my head was this addressing mode like: lda ($fb),y or lda ($fb,x) hell, i don't even remember was there a comma or a dot in front of the index register. much less how these two modes were called.

                                    H 1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      I first used pointers in asm, because it was the first thing other than basic i could really write code in for the 6502. I learned C later. I'm fine with them. it seems many other people aren't, hence the idea for the article. :)

                                      Real programmers use butterflies

                                      M Offline
                                      M Offline
                                      Martin ISDN
                                      wrote on last edited by
                                      #49

                                      > it seems many other people aren't, hence the idea for the article. than it's just a matter of time. just do it!

                                      1 Reply Last reply
                                      0
                                      • M Martin ISDN

                                        yeah, i was on the 6502 too. the most close to pointers out of the top of my head was this addressing mode like: lda ($fb),y or lda ($fb,x) hell, i don't even remember was there a comma or a dot in front of the index register. much less how these two modes were called.

                                        H Offline
                                        H Offline
                                        honey the codewitch
                                        wrote on last edited by
                                        #50

                                        YAY the bad old days!

                                        Real programmers use butterflies

                                        1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          What's so confusing about them? They point to a memory location. Think of an address as an index into a big array of bytes. No big. =)

                                          Real programmers use butterflies

                                          M Offline
                                          M Offline
                                          Member 10642872
                                          wrote on last edited by
                                          #51

                                          Honey, that is exactly why they are confusing! The problem is English and the really sloppy way programmers use English! Pointers do not actually "point" to a memory location. The fact that you can get to a data element in memory and that method that can be manipulated as if it were a number is a *compiler specific concept* in the C family of languages. And an incredibly stupid idea that creates tons of security vulnerabilities. NEVER, EVER use a pointer as if it were a number. ALWAYS use it as an abstract data type and you will avoid 99.9% of pointer type defects in your code. I am mentoring a young woman who is taking her first real programming class (Python *DOES NOT* count). --------------- Here is what I told her: Anyone who has ever written in a "proper" language like Pascal, Modula, PLM-86, or Ada or who studied actual Computer Science will tell you that a "pointer" is an abstract data type that is nothing more than a handle to some object in your program. There are *NO* operations defined for a pointer other than connection to some object, referencing an object (either an actual object in C++, C#, Ada, etc. or a struct or intrinsic in C) or copying a pointer to another pointer of the same type. You can literally use a "pointer" as a handle to carry data around in your program from one place to another. In some languages we use the word "reference" as a synonym for a pointer. I also gave her a physical example of how pointers can be used in linked lists. ---------------- Kernighan and Ritchie (bless their hearts) improperly called a data type by the CS name "pointer" when they should have named it an "address". They ARE NOT the same thing. In modern computers, that is absolutely the case because the "address" you get is just a virtual mapping of an actual address to some other thing that just happens to be a number (but you have to understand hardware to understand why that is). K&R (or some folks after them) also screwed up the keyword "static" which has two *completely different* meanings depending on context. The list of things screwed up in C is a long one! It is why the MISRA standard is necessary. C was just readable assembly language for the PDP-11 computer which got moved over time to other computers. Because you are forced on very small computers to play tricks in C/assembler in order to save data and code space, C has some really egregious history of confusing pointers with addresses and the fact that you can actually see a *real* computer underneath the virtu

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups