Author Topic: Value in watches not show up for array of char and char* variable  (Read 7387 times)

Offline kentut

  • Single posting newcomer
  • *
  • Posts: 4
Hello guys, I am a new codeblocks user, and I really need it for debugging my program consisting of many functions. However, the watches windows can't show up the value of my array of char variable and char* variable. Anyone knows what's wrong with my codeblocks? I have attached the screenshot here.

Thanks guys :)

Offline kentut

  • Single posting newcomer
  • *
  • Posts: 4
Re: Value in watches not show up for array of char and char* variable
« Reply #1 on: May 22, 2014, 05:57:21 am »
Here's screenshot of watches and my variable declaration..

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Value in watches not show up for array of char and char* variable
« Reply #2 on: May 22, 2014, 07:27:50 am »
I don't see any thing wrong. The local variable is not initialized, so random values are shown.
What is the expect value shown in the watch window?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline kentut

  • Single posting newcomer
  • *
  • Posts: 4
Re: Value in watches not show up for array of char and char* variable
« Reply #3 on: May 22, 2014, 07:43:52 am »
Actually the previous screenshot is a called function, variable a and b are parameters passed from the main program, but I can't find the values.
Here's the screenshot in the main program. Although I have initialized b[0] and b[1], it doesn't show the value in watches.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Value in watches not show up for array of char and char* variable
« Reply #4 on: May 22, 2014, 09:42:22 am »
Initialize b[0], b[1] to 0x30, 0x31 and try again please.

Offline kentut

  • Single posting newcomer
  • *
  • Posts: 4
Re: Value in watches not show up for array of char and char* variable
« Reply #5 on: May 22, 2014, 10:25:30 am »
Here the screenshot after I set b[0] to 0x30 and b[1] to 0x31. The value still strange....

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Value in watches not show up for array of char and char* variable
« Reply #6 on: May 22, 2014, 10:51:09 am »
Actually there is nothing strange with the values. 0x30 is '0' and 0x31 is '1' and the first 2 characters of 'b' array correctly shows these values. The rest are some uninitialized random values which may not correspond to printable characters in ASCII table even when initialized to some value. So there doesn't seem to be anything wrong with the CB part.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Value in watches not show up for array of char and char* variable
« Reply #7 on: May 22, 2014, 11:15:17 am »
char [] is the same as const char *, so gdb thinks it is a string and tries to print it as string. For function args and locals nothing could be done.
But if you want to inspect the variable as character array, then add it as a watch and right click -> properties -> treat as array (set start and count) and you're good to go.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]