INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

(OP)
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.




RE: VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

You can use ++ with pointers: it moves the pointer by the size of the item that it points to.

CODE

int* iptr;
int ia[20];

iptr = ia;  /* points to ia[0] */

int a = *iptr++; /* returns ia[0], then moves iptr to point to ia[1] */
int b = *++iptr; /* moves iptr to point to ia[2] and returns the value of ia[2] */
int c = ++(*iptr); /* increments value of ia[2] and returns the value of ia[2] */
int d = (*iptr)++;  /* returns the value of ia[2] then increments ia[2] */ 

RE: VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

(OP)
Thanks xwb, my training never included those methods of parentheses around a pointer as you show. So I was incrementing the address and not the value.
I just tried ++(*iptr); and (*iptr)++ to increment the value and they do work!

I had begun to wonder if the difference is that I am accessing a dll with unknown contents; I have never done this before.
Rather than a character array in my own code, I create a pointer to a pointer to a variable inside this dll (the recommended way by the manufacturer to access their internal values).
The final product will run on an embedded system but this first stage is to test my code in a simulation. My code compiles into a dll that is called by the main software.
It works though- thanks again.

Have you ever come across the Hex/decimal display option for debugging not working?

RE: VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

Some items like addresses are always displayed in hex. Others, like IP addresses, you'd normally display in decimal.

If a pointer value on a 16 bit machine was FB2E, and you knew that F000-FFFF was in ROM, then you'd know that it was pointing in the ROM. If you got -1234, it would be quite difficult to decipher.

If the IP address was 5001a8c0, it wouldn't be as recognizable as 192.168.1.80.

All forms have their uses.

RE: VS 2008 Hex display selection not working AND a tip on X++; increments by 4 !

(OP)
Ah yes this makes sense now, together with the fact that I was originally seeing the address.
Now that I use it properly I do see that the tooltip has both the pointer address AND a plus sign to expand and show the value!

Thanks again xwb. The "murky cloud" is lifting again. :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close