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

    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 Online
                  CPalliniC Online
                  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