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. Other Discussions
  3. Clever Code
  4. C - address of a pointer

C - address of a pointer

Scheduled Pinned Locked Moved Clever Code
lounge
14 Posts 7 Posters 5 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.
  • CPalliniC CPallini

    Well, it isn't such subtle. ;)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    L Offline
    L Offline
    Leisuresuit Larry
    wrote on last edited by
    #3

    It would be subtle if doSomething function were 200 lines instead of 2. :)

    CPalliniC 1 Reply Last reply
    0
    • L Leisuresuit Larry

      typedef struct
      {
      int i;
      } MyObj;

      Working code:

      void foo(MyObj* pObj)
      {
      /* pObj points to a valid struct */
      doSomething(&pObj);
      pObj->i = ...
      }

      Code that caused random crash:

      void foo(MyObj* pObj)
      {
      MyObj* p = pObj;
      doSomething(&p);
      pObj->i = ...
      }

      Reason:

      void doSomething(MyObj** p)
      {
      free(*p);
      *p = createNewObj();
      }

      M Offline
      M Offline
      Mladen Jankovic
      wrote on last edited by
      #4

      Leisuresuit Larry wrote:

      Reason:

      void doSomething(MyObj** p)
      {
      free(*p);
      *p = createNewObj();
      }

      As subtle as a 10 lb. sledge hammer. ;P

      [Genetic Algorithm Library]

      P J 2 Replies Last reply
      0
      • L Leisuresuit Larry

        It would be subtle if doSomething function were 200 lines instead of 2. :)

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #5

        Tell Mladen [^]. :-D

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • L Leisuresuit Larry

          typedef struct
          {
          int i;
          } MyObj;

          Working code:

          void foo(MyObj* pObj)
          {
          /* pObj points to a valid struct */
          doSomething(&pObj);
          pObj->i = ...
          }

          Code that caused random crash:

          void foo(MyObj* pObj)
          {
          MyObj* p = pObj;
          doSomething(&p);
          pObj->i = ...
          }

          Reason:

          void doSomething(MyObj** p)
          {
          free(*p);
          *p = createNewObj();
          }

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #6

          Would not really consider that subtle at all.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          1 Reply Last reply
          0
          • M Mladen Jankovic

            Leisuresuit Larry wrote:

            Reason:

            void doSomething(MyObj** p)
            {
            free(*p);
            *p = createNewObj();
            }

            As subtle as a 10 lb. sledge hammer. ;P

            [Genetic Algorithm Library]

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #7

            :laugh:

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            1 Reply Last reply
            0
            • L Leisuresuit Larry

              typedef struct
              {
              int i;
              } MyObj;

              Working code:

              void foo(MyObj* pObj)
              {
              /* pObj points to a valid struct */
              doSomething(&pObj);
              pObj->i = ...
              }

              Code that caused random crash:

              void foo(MyObj* pObj)
              {
              MyObj* p = pObj;
              doSomething(&p);
              pObj->i = ...
              }

              Reason:

              void doSomething(MyObj** p)
              {
              free(*p);
              *p = createNewObj();
              }

              S Offline
              S Offline
              StevenWalsh
              wrote on last edited by
              #8

              Its not subtle, but he learned... so its a good post

              1 Reply Last reply
              0
              • M Mladen Jankovic

                Leisuresuit Larry wrote:

                Reason:

                void doSomething(MyObj** p)
                {
                free(*p);
                *p = createNewObj();
                }

                As subtle as a 10 lb. sledge hammer. ;P

                [Genetic Algorithm Library]

                J Offline
                J Offline
                Jorgen Sigvardsson
                wrote on last edited by
                #9

                Mladen Jankovic wrote:

                10 lb. sledge hammer

                That's not a very manly sledge hammer now, is it? ;)

                -- Kein Mitleid Für Die Mehrheit

                M P 2 Replies Last reply
                0
                • J Jorgen Sigvardsson

                  Mladen Jankovic wrote:

                  10 lb. sledge hammer

                  That's not a very manly sledge hammer now, is it? ;)

                  -- Kein Mitleid Für Die Mehrheit

                  M Offline
                  M Offline
                  Mladen Jankovic
                  wrote on last edited by
                  #10

                  If it is about to hit you, it doesn't matter :)

                  [Genetic Algorithm Library]

                  1 Reply Last reply
                  0
                  • J Jorgen Sigvardsson

                    Mladen Jankovic wrote:

                    10 lb. sledge hammer

                    That's not a very manly sledge hammer now, is it? ;)

                    -- Kein Mitleid Für Die Mehrheit

                    P Offline
                    P Offline
                    Paul Conrad
                    wrote on last edited by
                    #11

                    No, it's not. You need a minimum 16 pound sledge hammer to get anything done. Had an old back patio, tried a 8 pound one, it just bounced off the concrete, but the 16 pounder, was a more productive story :rolleyes:

                    "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                    D M 2 Replies Last reply
                    0
                    • P Paul Conrad

                      No, it's not. You need a minimum 16 pound sledge hammer to get anything done. Had an old back patio, tried a 8 pound one, it just bounced off the concrete, but the 16 pounder, was a more productive story :rolleyes:

                      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #12

                      Paul Conrad wrote:

                      No, it's not. You need a minimum 16 pound sledge hammer to get anything done.

                      Depends what you're trying to do. Even a baby sledge will bust up thinner cast aluminum; when combined with a chisel up to at least a half inch thick. Probably more but I haven't had occasion to try since my early teens.

                      Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                      P 1 Reply Last reply
                      0
                      • D Dan Neely

                        Paul Conrad wrote:

                        No, it's not. You need a minimum 16 pound sledge hammer to get anything done.

                        Depends what you're trying to do. Even a baby sledge will bust up thinner cast aluminum; when combined with a chisel up to at least a half inch thick. Probably more but I haven't had occasion to try since my early teens.

                        Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #13

                        True, but using larger sledgehammers have more potential for more man points :-D

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                        1 Reply Last reply
                        0
                        • P Paul Conrad

                          No, it's not. You need a minimum 16 pound sledge hammer to get anything done. Had an old back patio, tried a 8 pound one, it just bounced off the concrete, but the 16 pounder, was a more productive story :rolleyes:

                          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                          M Offline
                          M Offline
                          Mladen Jankovic
                          wrote on last edited by
                          #14

                          Paul Conrad wrote:

                          tried a 8 pound one, it just bounced off the concrete

                          Amateurs! :)

                          [Genetic Algorithm Library]

                          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