3

If I put an int into Visual Studio's watch window, I can use various format additions to display it in different ways. So if I have "int myVariable = 10;" in the code, I can put "myVariable,x" into the watch window to have it display as hex. Likewise, "myVariable,c" makes it take the low byte and display it as a character. All the format tricks are documented here.

Now, with an int, I can do this:

(char*)(&myVariable),4

The ",4" says to display 4 values of the array. That will let me see the integer as a string of 4 characters -- this is some old software I'm working with that has a bunch of 4-character encodings. But I can't do that trick with a value returned from a function:

(char*)(&foo()),4

because I cannot take the address of the returned function. Watch window reports an error.

Does anyone know a trick where I can put a function into the watch window and format its integer return value as a string of characters?

srm
  • 3,062
  • 16
  • 30
  • 1
    If you just want to look at the value returned from a function, you can probably find a temporary variable that the return is assigned to. But I don't think you can "put a function into the watch window." Visual Studio would need to call your function every time it wants to update the display, and I don't think it does that kind of thing. – Tim Randall Oct 29 '18 at 16:00
  • 1
    @Tim putting a function in watch window works just fine. Yes, it calls the function. Very useful for debugging. – srm Oct 29 '18 at 16:09
  • 1
    I do not believe you can manipulate the function return value displayed in the locals window but you could copy the actual return value to the watch window and do so there. – SoronelHaetir Oct 29 '18 at 17:31
  • @SoronelHaetir I cannot take the address of an integer constant in the watch window, so I still cannot cast it as a (char*), so, no, I still cannot manipulate it to see it as four chars. (Even if that did work, it would still be problematic if I have to modify the watch window every time I break into code... the whole point is to have the watch show me the value as it changes. I just want to see that as characters.) – srm Oct 29 '18 at 19:50

0 Answers0