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. General Programming
  3. C / C++ / MFC
  4. Implication of assign a value at function entry

Implication of assign a value at function entry

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
16 Posts 5 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.
  • L Lost User

    Where is it getting overlayed?

    F Offline
    F Offline
    ForNow
    wrote on last edited by
    #3

    I made a DATA breakpoint in Visual Studio and the overlay was some where deep in Windows in ntdll I did a Call Stack and it wasn't in the function that BASSM was declared truth is at the very least since the value of BASSM is not being changed I should qualify it with a const to save compiler the trouble of initializing it every time

    L 1 Reply Last reply
    0
    • F ForNow

      I made a DATA breakpoint in Visual Studio and the overlay was some where deep in Windows in ntdll I did a Call Stack and it wasn't in the function that BASSM was declared truth is at the very least since the value of BASSM is not being changed I should qualify it with a const to save compiler the trouble of initializing it every time

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

      No, you should first find out where it is being overwritten and why. This error tells you that you have a bug in your code, so rather than try to hide it, you need to fix it. But without seeing more of your code it is difficult to guess what might be the cause.

      F 1 Reply Last reply
      0
      • L Lost User

        No, you should first find out where it is being overwritten and why. This error tells you that you have a bug in your code, so rather than try to hide it, you need to fix it. But without seeing more of your code it is difficult to guess what might be the cause.

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #5

        I could post all the code in the function but I don't think that would help I'll spend tonite trying to figure it and regardless I'll re-declare BASSM as const that still shouldn't stop the bug as its still a local stack variable thanks

        L 1 Reply Last reply
        0
        • F ForNow

          I could post all the code in the function but I don't think that would help I'll spend tonite trying to figure it and regardless I'll re-declare BASSM as const that still shouldn't stop the bug as its still a local stack variable thanks

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

          ForNow wrote:

          I'll re-declare BASSM as const

          Well, good luck, but you still have a bug in your code.

          F 2 Replies Last reply
          0
          • L Lost User

            ForNow wrote:

            I'll re-declare BASSM as const

            Well, good luck, but you still have a bug in your code.

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #7

            I’ll post it tommorow if I don’t get anywhere it is not clearly apperent as I never move anything into BASSM Thanks

            J 1 Reply Last reply
            0
            • F ForNow

              I’ll post it tommorow if I don’t get anywhere it is not clearly apperent as I never move anything into BASSM Thanks

              J Offline
              J Offline
              jeron1
              wrote on last edited by
              #8

              For clarification the value of BASSM is different at the end of the process_trace() method, than the initialized value?

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

              F 1 Reply Last reply
              0
              • J jeron1

                For clarification the value of BASSM is different at the end of the process_trace() method, than the initialized value?

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #9

                the first byte of the BASSM X'0C' gets overlayed not sure where I am going to have to step thru process_trace and check BASSM intermittently Thanks

                J L 2 Replies Last reply
                0
                • F ForNow

                  the first byte of the BASSM X'0C' gets overlayed not sure where I am going to have to step thru process_trace and check BASSM intermittently Thanks

                  J Offline
                  J Offline
                  jeron1
                  wrote on last edited by
                  #10

                  If it get overwritten consistently, stepping through the method is the way to go.

                  "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                  1 Reply Last reply
                  0
                  • F ForNow

                    the first byte of the BASSM X'0C' gets overlayed not sure where I am going to have to step thru process_trace and check BASSM intermittently Thanks

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

                    Set a watchpoint on it in the debugger: Watch and QuickWatch Windows[^]

                    F 1 Reply Last reply
                    0
                    • L Lost User

                      Set a watchpoint on it in the debugger: Watch and QuickWatch Windows[^]

                      F Offline
                      F Offline
                      ForNow
                      wrote on last edited by
                      #12

                      Thanks :)

                      1 Reply Last reply
                      0
                      • F ForNow

                        Hi I am getting a local variable overlayed now I am beginning to think it maybe because of the way I declared it for example void process_trace() { char BASSM[2] = {0X0C, 0XEF}; This is still considered a local variable even though its assigned value since I didn't use the key word static So I guess on entry to the function the complier re-initializes the value everytime I guess I am thinking since this variable is some how being overlayed and I am not changing the value I should make it static Thanks

                        C Offline
                        C Offline
                        charlieg
                        wrote on last edited by
                        #13

                        I'm not sure what the others are thinking, but context is important here. You have defined BASSM within process_trace. Once you get to the bottom of process_trace (that little curly brace you step over), that context is lost. From a code point of view, it no longer exists. From a memory point of view, it BASSM may reference memory that still contains the values you init'd it too, but you cannot depend on that. Context is key here.

                        Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

                        CPalliniC 1 Reply Last reply
                        0
                        • C charlieg

                          I'm not sure what the others are thinking, but context is important here. You have defined BASSM within process_trace. Once you get to the bottom of process_trace (that little curly brace you step over), that context is lost. From a code point of view, it no longer exists. From a memory point of view, it BASSM may reference memory that still contains the values you init'd it too, but you cannot depend on that. Context is key here.

                          Charlie Gilley <italic>Stuck in a dysfunctional matrix from which I must escape... "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

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

                          Indeed.:thumbsup:

                          In testa che avete, signor di Ceprano?

                          1 Reply Last reply
                          0
                          • L Lost User

                            ForNow wrote:

                            I'll re-declare BASSM as const

                            Well, good luck, but you still have a bug in your code.

                            F Offline
                            F Offline
                            ForNow
                            wrote on last edited by
                            #15

                            There was a VFETCH macro which basically copied over data from the Mainframe emulated storage to your program the macro had a length however it would append a NULL (CString Style) at the end so even though I specified 4 bytes it put a null at the 5 th byte The local storage the way it is laid out by the compiler is not the way it’s declared in the function so even though the area the VFETCH macro was using wasn’t declared after the BASSM the compiler laid it out that way and the VFETCH overlaid the 1st byte of BASSM I fixed this problem but I also moved the BASSM to global storage by making it static Thanks for all the help

                            L 1 Reply Last reply
                            0
                            • F ForNow

                              There was a VFETCH macro which basically copied over data from the Mainframe emulated storage to your program the macro had a length however it would append a NULL (CString Style) at the end so even though I specified 4 bytes it put a null at the 5 th byte The local storage the way it is laid out by the compiler is not the way it’s declared in the function so even though the area the VFETCH macro was using wasn’t declared after the BASSM the compiler laid it out that way and the VFETCH overlaid the 1st byte of BASSM I fixed this problem but I also moved the BASSM to global storage by making it static Thanks for all the help

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

                              X|

                              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