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. Pointers or references?

Pointers or references?

Scheduled Pinned Locked Moved The Lounge
jsonhelpquestionlearning
36 Posts 16 Posters 2 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.
  • S Stan Shannon

    Thanks, Mick. I thought that was fairly discriptive of some of the code I've had to work on in my lifetime. The biggest problem with pointers is that they give lazy programmers the power to be lazy and get away with it. How's the job search going? If you are still unemployed then you and I are now in the same boat. Except that I just up and quit my job. I intend to spend two or three months living off my savings, mooching off my wife, and upgrading my skills a bit then trying the job market again. I might end up flipping burgers for the rest of my career, and raising my kids as trailer trash, but I've just finally had it with the bad management and unrealistic expectations that pervade the software industry. I think if I can't get something going on my own, I am going to get completely out of the business.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #27

    Stan Shannon wrote: How's the job search going? Sat on my arse for the last 2 months and prettty much did fuck all. Had My, Mother In-law, Wifes, Father In-laws and Daughters birthdays in that time so did a lot of preparing and entertaining. Got no savings so spending myself further into debt. Though I did spend a couple of weeks in a factory, the manual non-thinking work was good for a change. Would be doing it now as they came back this week but I have a spasming muscle in my back. Physio trying to fix it now. Have just finished version 0.11 of my résumé and have sent it to a couple of close friends for perusal. After that I will post a link here in the lounge for pointers to get it as shiny as possible and then it's serious job hunting time. Michael Martin Australia mmartin@netspace.net.au "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

    J R 2 Replies Last reply
    0
    • E Eddie Velasquez

      You forgot to mention that references cannot be "reseated", that is, you can't change the entity the reference "points" to. Foot-and-Mouth disease is believed to be the first virus unable to spread through Microsoft Outlook

      R Offline
      R Offline
      Roger Wright new
      wrote on last edited by
      #28

      Eddie Velasquez wrote: Foot-and-Mouth disease is believed to be the first virus unable to spread through Microsoft Outlook Its close relative, Foot in Mouth disease, does not appear to have this limitation.

      1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        (IMHO: We are splitting hairs here) Sure we are! That's the fun of it ;) Take this lightly, it's obvious that we both know exactly what we're talking bout. So, to continue with this exercise of exegesis, you seem to state that the standard does not say

        a reference to a null object cannot exist

        but instead it says

        a reference to a null object cannot exist in a well-defined program.

        So the standard implies that

        references to null objects can only exist in badly-defined programs.

        Now I'm curious as to what a "well-defined" program is (is it the same as a correct program?) Cheers! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        T Offline
        T Offline
        Thomas Freudenberg
        wrote on last edited by
        #29

        Joaquín M López Muñoz wrote: Now I'm curious as to what a "well-defined" program is (is it the same as a correct program?) Obviously, a well-defined program is a program, where no references to null objects exist. ;P Regards Thomas Finally with Sonork id: 100.10453 Thömmi


        Disclaimer:
        Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.

        1 Reply Last reply
        0
        • S S Spenz

          What do you like more in your code? Functions with pointers or references parameters? I don't talk about required e.g. API function stuff but about self-defined functions. I think pointers look much better than this ugly & ;) . Of course sometimes you have no choice but if what would you choose? ----------------------------------------- I'm a signature virus. Copy me to your sig and help me spread...

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #30

          S. Spenz wrote: What do you like more in your code? Functions with pointers or references parameters?    Here is a small often overlooked thought:  Consider that you are building a DLL for external use by others.  Do you use pointers or references in your parameter lists?    (Possible reason why you should not: the C++ standard says that the implementation of references is implementation-dependent, meaning depending largly on you compiler suite, correct?  So what happens when code generated with one compiler tries to use code generated by another? Like Borland <-> CV++, or VC++ <-> MinGW?)    Peace! -=- James.

          J 1 Reply Last reply
          0
          • J James R Twine

            S. Spenz wrote: What do you like more in your code? Functions with pointers or references parameters?    Here is a small often overlooked thought:  Consider that you are building a DLL for external use by others.  Do you use pointers or references in your parameter lists?    (Possible reason why you should not: the C++ standard says that the implementation of references is implementation-dependent, meaning depending largly on you compiler suite, correct?  So what happens when code generated with one compiler tries to use code generated by another? Like Borland <-> CV++, or VC++ <-> MinGW?)    Peace! -=- James.

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #31

            If only references were the greatest problem in intercompiler communication! (sigh) Unfortunately (or not?), there's an enormous set of implementation details due to wich which code generated by two compilers can not be mixed. To name a few: name mangling, member function calling convention, class layout, virtual table implementation... Reference implementation is but a tiny drop of water in the middle of this ocean of incompatibilities. In case you're interested, there's some effort going on on different forums about the problem of defining a compiler interoperable C++ Aplication Binary Interface. Lots of info on the net, just type "C++ ABI" in your favorite search engine. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            J 1 Reply Last reply
            0
            • L Lost User

              Stan Shannon wrote: How's the job search going? Sat on my arse for the last 2 months and prettty much did fuck all. Had My, Mother In-law, Wifes, Father In-laws and Daughters birthdays in that time so did a lot of preparing and entertaining. Got no savings so spending myself further into debt. Though I did spend a couple of weeks in a factory, the manual non-thinking work was good for a change. Would be doing it now as they came back this week but I have a spasming muscle in my back. Physio trying to fix it now. Have just finished version 0.11 of my résumé and have sent it to a couple of close friends for perusal. After that I will post a link here in the lounge for pointers to get it as shiny as possible and then it's serious job hunting time. Michael Martin Australia mmartin@netspace.net.au "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

              J Offline
              J Offline
              jkgh
              wrote on last edited by
              #32

              Sorry to but in but .. good luck to both of you. I've enjoyed reading your combined posts for the last year or so. Kind regards.

              1 Reply Last reply
              0
              • L Lost User

                Stan Shannon wrote: How's the job search going? Sat on my arse for the last 2 months and prettty much did fuck all. Had My, Mother In-law, Wifes, Father In-laws and Daughters birthdays in that time so did a lot of preparing and entertaining. Got no savings so spending myself further into debt. Though I did spend a couple of weeks in a factory, the manual non-thinking work was good for a change. Would be doing it now as they came back this week but I have a spasming muscle in my back. Physio trying to fix it now. Have just finished version 0.11 of my résumé and have sent it to a couple of close friends for perusal. After that I will post a link here in the lounge for pointers to get it as shiny as possible and then it's serious job hunting time. Michael Martin Australia mmartin@netspace.net.au "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

                R Offline
                R Offline
                Roger Allen
                wrote on last edited by
                #33

                Michael Martin wrote: then it's serious job hunting time Sorry, I am still not available to attend interviews for you :-D Roger Allen Sonork 100.10016

                L 1 Reply Last reply
                0
                • T Tim Smith

                  But to be honest I'm not really a fan of references. Beleiving that a reference always "points" to something is dangerous: Not true at all. The only way to do this gets you into the realm of undefined behavior and thus is inherently bad programming. Tim Smith Descartes Systems Sciences, Inc.

                  M Offline
                  M Offline
                  Maximilian Hanel
                  wrote on last edited by
                  #34

                  Tim Smith wrote: Not true at all. The only way to do this gets you into the realm of undefined behavior and thus is inherently bad programming. I totally agree with you that passing a "NULL reference" is bad programming. But what's the difference in passing a NULL reference and passing a NULL pointer? IMHO passing a NULL pointer is as bad as passing a "NULL reference". Passing a "NULL reference" results in an so called "undefined behaviour" (in other words the programm may crash) and passing NULL pointer results in a "defined behaviour" (the programm defenitely will crash). So why should references be safer than pointers? Assume there is an existing function called GetBar wich returns a pointer to a CBar. Additionally you wrote your own function Baz wich accepts a reference to a CBar:

                  CBar* GetBar();
                  void Baz(CBar& bar);
                  //[...]
                  CBar* pBar=GetBar();
                  Baz(*pBar);

                  Is Baz now "safer" because we accept a reference to a CBar instead of a pointer to CBar? I don't think so. Please don't get me wrong. I'm not the person who tells the world not using references. I'm using references, too (but I'm not a fan). The point is that references IMHO are not in the least safer than pointers. Maybe the chance that you pass a "NULL reference" is more less. But this doesn't make a reference itself safer. Have a nice day Max

                  1 Reply Last reply
                  0
                  • J Joaquin M Lopez Munoz

                    If only references were the greatest problem in intercompiler communication! (sigh) Unfortunately (or not?), there's an enormous set of implementation details due to wich which code generated by two compilers can not be mixed. To name a few: name mangling, member function calling convention, class layout, virtual table implementation... Reference implementation is but a tiny drop of water in the middle of this ocean of incompatibilities. In case you're interested, there's some effort going on on different forums about the problem of defining a compiler interoperable C++ Aplication Binary Interface. Lots of info on the net, just type "C++ ABI" in your favorite search engine. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                    J Offline
                    J Offline
                    James R Twine
                    wrote on last edited by
                    #35

                    Joaquín M López Muñoz wrote: Unfortunately (or not?), there's an enormous set of implementation details due to wich which code generated by two compilers can not be mixed. To name a few: name mangling, member function calling convention, class layout, virtual table implementation... Reference implementation is but a tiny drop of water in the middle of this ocean of incompatibilities.    That assumes that I am only talking about exporting entire classes, or member functions.    I am just talking about doing things as simple as just writing a "plain" DLL that exports a few non-member functions (which can be referenced by ordinal, or alias).  Why do I ask about this?  Because I have seen it done before :(    I just wanted to hear other thoughts on the wisdom (or lack of) in doing so.    Peace! -=- James.

                    1 Reply Last reply
                    0
                    • R Roger Allen

                      Michael Martin wrote: then it's serious job hunting time Sorry, I am still not available to attend interviews for you :-D Roger Allen Sonork 100.10016

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #36

                      Roger Allen wrote: Sorry, I am still not available to attend interviews for you :-D Well I wouldn't have you anyway you lazy Pommy bastard. You didn't write the résumé for me, so you haven't earnt the right to attend the interview's that will follow. ;P Michael Martin Australia mmartin@netspace.net.au "Don't belong. Never join. Think for yourself. Peace" - Victor Stone

                      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