Code::Blocks Forums

User forums => Help => Topic started by: kentut on May 22, 2014, 05:56:02 am

Title: Value in watches not show up for array of char and char* variable
Post by: kentut on May 22, 2014, 05:56:02 am
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 :)
Title: Re: Value in watches not show up for array of char and char* variable
Post by: kentut on May 22, 2014, 05:57:21 am
Here's screenshot of watches and my variable declaration..
Title: Re: Value in watches not show up for array of char and char* variable
Post by: ollydbg 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?
Title: Re: Value in watches not show up for array of char and char* variable
Post by: kentut 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.
Title: Re: Value in watches not show up for array of char and char* variable
Post by: scarphin on May 22, 2014, 09:42:22 am
Initialize b[0], b[1] to 0x30, 0x31 and try again please.
Title: Re: Value in watches not show up for array of char and char* variable
Post by: kentut 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....
Title: Re: Value in watches not show up for array of char and char* variable
Post by: scarphin 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.
Title: Re: Value in watches not show up for array of char and char* variable
Post by: oBFusCATed 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.