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. Managed C++/CLI
  4. Sizeof out of scope?

Sizeof out of scope?

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorialquestion
11 Posts 3 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.
  • X Offline
    X Offline
    Xpnctoc
    wrote on last edited by
    #1

    Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed: ? sizeof(bool) which gave me the message error: identifier 'sizeof' out of scope I can't seem to find documentation for this anywhere. Thanks.

    M L X 3 Replies Last reply
    0
    • X Xpnctoc

      Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed: ? sizeof(bool) which gave me the message error: identifier 'sizeof' out of scope I can't seem to find documentation for this anywhere. Thanks.

      M Offline
      M Offline
      Michel Godfroid
      wrote on last edited by
      #2

      In C#, and in C++, sizeof is an operator, and not a function. It is something that is calculated at compile-time, and not at run-time. As such, the debugger does not know the sizeof operator, as it is a language-specific way of expressing an operator. The way your type your expression, the debugger will interpret it as: Call Debug.Print(sizeof(bool)) Since the sizeof function does not exist, you get an out of scope error message.

      1 Reply Last reply
      0
      • X Xpnctoc

        Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed: ? sizeof(bool) which gave me the message error: identifier 'sizeof' out of scope I can't seem to find documentation for this anywhere. Thanks.

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

        Xpnctoc wrote:

        All I keep getting are stupid error messages.

        On the contrary, you are getting helpful error messages. You just need to use the information to help you figure out what is happening.

        It's time for a new signature.

        1 Reply Last reply
        0
        • X Xpnctoc

          Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed: ? sizeof(bool) which gave me the message error: identifier 'sizeof' out of scope I can't seem to find documentation for this anywhere. Thanks.

          X Offline
          X Offline
          Xpnctoc
          wrote on last edited by
          #4

          I have never done this before, but I'm going to have to disagree with nearly everything that has been put forth in the responses so far. I created a new scratch C++/CLI project to see if there was a problem in the way my other C++ project was configured. However, using sizeof in the Immediate window continues to produce the "out of scope" error. Then I created a new scratch C# project to put Michel's response to the test. When I type ? sizeof(bool) in the Immediate window, it returns an output of "1". So whatever is going on with "sizeof" in C++/CLI is not extendable to C#. Regarding Richard's comment about me calling the "out of scope" message stupid, I'm going to stand by what I said. "Sizeof" -- especially if Michel is right calling it an operator rather than a function -- is part of the language. It's not some custom function of some special class where an extra reference is needed. So how can it ever be out of scope? In that regard, the message makes no sense. Therefore it is utterly unhelpful. That makes it, IMHO, fully deserving of the label "stupid".

          M 1 Reply Last reply
          0
          • X Xpnctoc

            I have never done this before, but I'm going to have to disagree with nearly everything that has been put forth in the responses so far. I created a new scratch C++/CLI project to see if there was a problem in the way my other C++ project was configured. However, using sizeof in the Immediate window continues to produce the "out of scope" error. Then I created a new scratch C# project to put Michel's response to the test. When I type ? sizeof(bool) in the Immediate window, it returns an output of "1". So whatever is going on with "sizeof" in C++/CLI is not extendable to C#. Regarding Richard's comment about me calling the "out of scope" message stupid, I'm going to stand by what I said. "Sizeof" -- especially if Michel is right calling it an operator rather than a function -- is part of the language. It's not some custom function of some special class where an extra reference is needed. So how can it ever be out of scope? In that regard, the message makes no sense. Therefore it is utterly unhelpful. That makes it, IMHO, fully deserving of the label "stupid".

            M Offline
            M Offline
            Michel Godfroid
            wrote on last edited by
            #5

            I still stand by my answer. In c#, the debugger can use the .Net compiler support libraries to compile your statement on the fly. In native code, there is no such thing. I must admit that I've never tried it in C#, but in unmanaged C++, this behaviour is 'expected'. Whether to label it stupid, is is entirely up to you.

            X 1 Reply Last reply
            0
            • M Michel Godfroid

              I still stand by my answer. In c#, the debugger can use the .Net compiler support libraries to compile your statement on the fly. In native code, there is no such thing. I must admit that I've never tried it in C#, but in unmanaged C++, this behaviour is 'expected'. Whether to label it stupid, is is entirely up to you.

              X Offline
              X Offline
              Xpnctoc
              wrote on last edited by
              #6

              But I'm not dealing with strictly unmanaged C++ anyway. My project is a "mixed mode" C++/CLI project. By definition, the project has to be .NET-aware. And the breakpoint that I set was actually in a managed code section (i.e., in one of the Windows Forms event handlers). So why can't it use the same .NET compilation support as C#? Even if the project was 100% unmanaged, the compiler still has to convert a sizeof call into a useable via some kind of library. Why can't the debugger make use of that part of the compiler? I don't label the problem itself as "stupid". I obviously don't understand it and was trying to get some clarification. What I do label as "stupid" is the "out of scope" error message. It just seems to me that there has to be a lot better/more helpful wording for when this error condition is encountered -- something like: "'Sizeof' operator is unsupported in debugging." If they had a truly informative error message like that, I wouldn't have had to start this post to begin with. It still wouldn't answer the "why" questions, but at least it would be a lot less cryptic than some vague "out of scope" message. After all, if sizeof is an operator rather than a function as you originally suggested, how the heck can an operator -- a built-in part of the language -- be out of scope?

              L 1 Reply Last reply
              0
              • X Xpnctoc

                But I'm not dealing with strictly unmanaged C++ anyway. My project is a "mixed mode" C++/CLI project. By definition, the project has to be .NET-aware. And the breakpoint that I set was actually in a managed code section (i.e., in one of the Windows Forms event handlers). So why can't it use the same .NET compilation support as C#? Even if the project was 100% unmanaged, the compiler still has to convert a sizeof call into a useable via some kind of library. Why can't the debugger make use of that part of the compiler? I don't label the problem itself as "stupid". I obviously don't understand it and was trying to get some clarification. What I do label as "stupid" is the "out of scope" error message. It just seems to me that there has to be a lot better/more helpful wording for when this error condition is encountered -- something like: "'Sizeof' operator is unsupported in debugging." If they had a truly informative error message like that, I wouldn't have had to start this post to begin with. It still wouldn't answer the "why" questions, but at least it would be a lot less cryptic than some vague "out of scope" message. After all, if sizeof is an operator rather than a function as you originally suggested, how the heck can an operator -- a built-in part of the language -- be out of scope?

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

                Xpnctoc wrote:

                the compiler still has to convert a sizeof call into a useable via some kind of library.

                No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like +.

                Xpnctoc wrote:

                If they had a truly informative error message

                I think this rant should be directed at Microsoft.

                It's time for a new signature.

                X 1 Reply Last reply
                0
                • L Lost User

                  Xpnctoc wrote:

                  the compiler still has to convert a sizeof call into a useable via some kind of library.

                  No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like +.

                  Xpnctoc wrote:

                  If they had a truly informative error message

                  I think this rant should be directed at Microsoft.

                  It's time for a new signature.

                  X Offline
                  X Offline
                  Xpnctoc
                  wrote on last edited by
                  #8

                  Richard MacCutchan wrote:

                  No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like +.

                  And yet other operators like + and == are fully accessible within the Immediate window. You said it yourself... there is no associated library because sizeof is an operator. How can any operator -- an integral part of the language -- ever be out of scope? I mean, wouldn't it strike you as really messed up if suddenly you got an error message saying + was "out of scope"? If 'sizeof' is only evaluated at compile time and treated as a constant in the executable, and Immediate cannot access it as part of the available evaluation syntax, then it seems to me 'sizeof' would be better termed as a MACRO than an operator -- just like using the #define precompiler directive.

                  L 1 Reply Last reply
                  0
                  • X Xpnctoc

                    Richard MacCutchan wrote:

                    No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like +.

                    And yet other operators like + and == are fully accessible within the Immediate window. You said it yourself... there is no associated library because sizeof is an operator. How can any operator -- an integral part of the language -- ever be out of scope? I mean, wouldn't it strike you as really messed up if suddenly you got an error message saying + was "out of scope"? If 'sizeof' is only evaluated at compile time and treated as a constant in the executable, and Immediate cannot access it as part of the available evaluation syntax, then it seems to me 'sizeof' would be better termed as a MACRO than an operator -- just like using the #define precompiler directive.

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

                    Well, you are right in all you say and I am (partly) wrong. My biggest mistake was to take your query at face value, rather than checking what results I get. I have just tested this by adding sizeof(variable) in my watch window while debugging and it shows the correct value. So, we go back to the original problem that you are seeing: where exactly, and under what conditions, are you typing your query?

                    It's time for a new signature.

                    X 1 Reply Last reply
                    0
                    • L Lost User

                      Well, you are right in all you say and I am (partly) wrong. My biggest mistake was to take your query at face value, rather than checking what results I get. I have just tested this by adding sizeof(variable) in my watch window while debugging and it shows the correct value. So, we go back to the original problem that you are seeing: where exactly, and under what conditions, are you typing your query?

                      It's time for a new signature.

                      X Offline
                      X Offline
                      Xpnctoc
                      wrote on last edited by
                      #10

                      The actual query I'm using is what I originally listed: ? sizeof(bool) rather than ? sizeof(boolean_variable) To reproduce what I'm getting: 1. Make a new project: C++, CLR, Windows Forms Application 2. Double-click the form to generate the Form_Load event. 3. Put a break point on the closing brace of the Form_Load event handler method. 4. Run the application. 5. When the break point is hit, bring up the Immediate window and type "? sizeof(bool)" (without the quotes, of course) 6. Result is: "error: identifier 'sizeof' is out of scope" If you take identical steps but use a C# project, you will get an output of "1". Michel had mentioned that we should expect the error message in unmanaged C++, but from the steps I've outlined above, we're not dealing with unmanaged C++. We're dealing with CLR-aware C++, so it seems to me we should have the same .NET support as C#. BTW, this is under VS 2008 (and Windows 7 64-bit if that makes a difference).

                      L 1 Reply Last reply
                      0
                      • X Xpnctoc

                        The actual query I'm using is what I originally listed: ? sizeof(bool) rather than ? sizeof(boolean_variable) To reproduce what I'm getting: 1. Make a new project: C++, CLR, Windows Forms Application 2. Double-click the form to generate the Form_Load event. 3. Put a break point on the closing brace of the Form_Load event handler method. 4. Run the application. 5. When the break point is hit, bring up the Immediate window and type "? sizeof(bool)" (without the quotes, of course) 6. Result is: "error: identifier 'sizeof' is out of scope" If you take identical steps but use a C# project, you will get an output of "1". Michel had mentioned that we should expect the error message in unmanaged C++, but from the steps I've outlined above, we're not dealing with unmanaged C++. We're dealing with CLR-aware C++, so it seems to me we should have the same .NET support as C#. BTW, this is under VS 2008 (and Windows 7 64-bit if that makes a difference).

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

                        OK, I can reproduce this under VS2010 (full and Express versions). I guess the only way forward is to raise this with Microsoft. I'm still confused as to why this happens with managed but not unmanaged code; I guess two different debuggers.

                        It's time for a new signature.

                        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