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. Variable value is always's zero, no matter what you do! [modified]

Variable value is always's zero, no matter what you do! [modified]

Scheduled Pinned Locked Moved Clever Code
helpc++phpcomarchitecture
9 Posts 4 Posters 3 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.
  • N Offline
    N Offline
    Nibu babu thomas
    wrote on last edited by
    #1

    Don't know if this is a subtle bug, but anyway... Recently a friend of mine (sitting just behind me) had a strange problem. I wrote an inline function which was like...

    void SetBlah( const bool IsBlah ) { m_IsBlah = IsBlah; }

    Now he was using this function since we work for the same project! So he had a value 1 for IsBlah when calling this function but no matter what he did m_IsBlah always had the value zero! He spent half a day trying to solve this issue, I too joined him in this venture. We thought it has got something to do with inlining the function call so we made it non inlined but this didn't solve the issue. No matter what we did still the value was zero, we tried rebuilding the project but no effect whatsoever. I tried running the code on my machine and it was fine, working as it should be! So in the end I found out the problem? But before I post the answer here, any idea what could be the reason? Answer He had a statement in his watch window like... theStaticLongNameObject.m_IsBlah = 0; This expression prevented the value from changing. :) Also we can't see the full expression in watch window because of the variable's long name!

    Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

    modified on Thursday, May 8, 2008 5:25 AM

    CPalliniC J 2 Replies Last reply
    0
    • N Nibu babu thomas

      Don't know if this is a subtle bug, but anyway... Recently a friend of mine (sitting just behind me) had a strange problem. I wrote an inline function which was like...

      void SetBlah( const bool IsBlah ) { m_IsBlah = IsBlah; }

      Now he was using this function since we work for the same project! So he had a value 1 for IsBlah when calling this function but no matter what he did m_IsBlah always had the value zero! He spent half a day trying to solve this issue, I too joined him in this venture. We thought it has got something to do with inlining the function call so we made it non inlined but this didn't solve the issue. No matter what we did still the value was zero, we tried rebuilding the project but no effect whatsoever. I tried running the code on my machine and it was fine, working as it should be! So in the end I found out the problem? But before I post the answer here, any idea what could be the reason? Answer He had a statement in his watch window like... theStaticLongNameObject.m_IsBlah = 0; This expression prevented the value from changing. :) Also we can't see the full expression in watch window because of the variable's long name!

      Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      modified on Thursday, May 8, 2008 5:25 AM

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

      How is m_IsBlah declared?

      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

      In testa che avete, signor di Ceprano?

      N 1 Reply Last reply
      0
      • CPalliniC CPallini

        How is m_IsBlah declared?

        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

        N Offline
        N Offline
        Nibu babu thomas
        wrote on last edited by
        #3

        CPallini wrote:

        How is m_IsBlah declared?

        private: bool m_IsBlah; Well as a hint, it will work fine if it's not being debugged! ;)

        Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

        CPalliniC 1 Reply Last reply
        0
        • N Nibu babu thomas

          CPallini wrote:

          How is m_IsBlah declared?

          private: bool m_IsBlah; Well as a hint, it will work fine if it's not being debugged! ;)

          Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

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

          But it is also system dependent, I suppose: my debugger shows it working fine. :)

          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

          In testa che avete, signor di Ceprano?

          N 1 Reply Last reply
          0
          • CPalliniC CPallini

            But it is also system dependent, I suppose: my debugger shows it working fine. :)

            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

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            CPallini wrote:

            But it is also system dependent, I suppose: my debugger shows it working fine. [Smile]

            No, :) It's not system dependent, but it's just a stupid mistake done in one of the debugger windows(can't give a better hint than this one).

            Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

            M 1 Reply Last reply
            0
            • N Nibu babu thomas

              CPallini wrote:

              But it is also system dependent, I suppose: my debugger shows it working fine. [Smile]

              No, :) It's not system dependent, but it's just a stupid mistake done in one of the debugger windows(can't give a better hint than this one).

              Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

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

              m_IsBlah = false in watch window?

              Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

              N 1 Reply Last reply
              0
              • M Mladen Jankovic

                m_IsBlah = false in watch window?

                Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                N Offline
                N Offline
                Nibu babu thomas
                wrote on last edited by
                #7

                Mladen Jankovic wrote:

                m_IsBlah = false in watch window?

                Yes, good guess! :)

                Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

                CPalliniC 1 Reply Last reply
                0
                • N Nibu babu thomas

                  Mladen Jankovic wrote:

                  m_IsBlah = false in watch window?

                  Yes, good guess! :)

                  Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

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

                  I had a quite similar Visual Studio behaviour right now. While debugging an executable (DEBUG build) I stepped inside the code of a DLL (RELEASE build) and there appeared such inconsistecies. My (empirical) solution was building the DEBUG version of the DLL. I don't know if the above puts some light into your problem. :)

                  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

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • N Nibu babu thomas

                    Don't know if this is a subtle bug, but anyway... Recently a friend of mine (sitting just behind me) had a strange problem. I wrote an inline function which was like...

                    void SetBlah( const bool IsBlah ) { m_IsBlah = IsBlah; }

                    Now he was using this function since we work for the same project! So he had a value 1 for IsBlah when calling this function but no matter what he did m_IsBlah always had the value zero! He spent half a day trying to solve this issue, I too joined him in this venture. We thought it has got something to do with inlining the function call so we made it non inlined but this didn't solve the issue. No matter what we did still the value was zero, we tried rebuilding the project but no effect whatsoever. I tried running the code on my machine and it was fine, working as it should be! So in the end I found out the problem? But before I post the answer here, any idea what could be the reason? Answer He had a statement in his watch window like... theStaticLongNameObject.m_IsBlah = 0; This expression prevented the value from changing. :) Also we can't see the full expression in watch window because of the variable's long name!

                    Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

                    modified on Thursday, May 8, 2008 5:25 AM

                    J Offline
                    J Offline
                    Jijo Raj
                    wrote on last edited by
                    #9

                    And the last page of story - I'm that unlucky friend who sits nearby him. :rolleyes: Regards, Jijo.

                    _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                    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