Yorkshireman2
Programmer
I'm using vs2008 programming in C code.
First my question then a discovery that I hope will help the rusty c programmers out there.
In debugging C code with VS2008, the tool tip over the variable (or in a watch window) is in hex! I tried selecting the right-click hex display option to on and off again but it still shows hex whatever I select.
Despite the numerous tips on these forums to change the hex display option it does nothing in my VS2008. Why? ...and how do I change it to decimal?
NOW the TIP...
I was puzzled by the discovery that addition and subtraction changed my variable by 4 instead of 1.
I tried x++; and it increased it by 4
I tried x+=1; it increased by 4
I tried x=x+1 it increased by 4
What was wrong? Well, this is the first time I have done some c code for a long while although I'm not new to it- just first time in vs2008
Why was it adding 4 instead of 1?
Well my variable was created as a pointer to a pointer but I was using the variable name and NOT the value pointed to.
So It finally came back to me about dereferencing pointers and I tried *x++ and that correctly points to the value that is pointed to by the variable.
(before it was changing the address of the pointer ! and thus it was changing by 4 each time because these addresses do move by 4.
Not the end of it though... then I found the ++ operator was not working with the new statement. So then I figured out by trial and error that you cannot use ++ with a pointer.
I changed it to *x = *x +1 and it works as I expect. So anyone else who is rusty note this.. the nice short-cuts like ++ do not work on the values when you are using pointers.
First my question then a discovery that I hope will help the rusty c programmers out there.
In debugging C code with VS2008, the tool tip over the variable (or in a watch window) is in hex! I tried selecting the right-click hex display option to on and off again but it still shows hex whatever I select.
Despite the numerous tips on these forums to change the hex display option it does nothing in my VS2008. Why? ...and how do I change it to decimal?
NOW the TIP...
I was puzzled by the discovery that addition and subtraction changed my variable by 4 instead of 1.
I tried x++; and it increased it by 4
I tried x+=1; it increased by 4
I tried x=x+1 it increased by 4
What was wrong? Well, this is the first time I have done some c code for a long while although I'm not new to it- just first time in vs2008
Why was it adding 4 instead of 1?
Well my variable was created as a pointer to a pointer but I was using the variable name and NOT the value pointed to.
So It finally came back to me about dereferencing pointers and I tried *x++ and that correctly points to the value that is pointed to by the variable.
(before it was changing the address of the pointer ! and thus it was changing by 4 each time because these addresses do move by 4.
Not the end of it though... then I found the ++ operator was not working with the new statement. So then I figured out by trial and error that you cannot use ++ with a pointer.
I changed it to *x = *x +1 and it works as I expect. So anyone else who is rusty note this.. the nice short-cuts like ++ do not work on the values when you are using pointers.