Sign in to follow this  

Weird problem in C++ with .NET 2003

This topic is 4480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tryed to port one of my projects from Visual Studio 6 to Visual Studio .NET 2003. All went ok but when I've ran the project there were some crashes (apparently without any reason). All problems were somethilg like that:
class myClass
{
public:
.....
    inline int GetValue()         {return myValue;}
.....
protected:
.....
    int myValue;

}

.....
.....
 int a;
 myClass *cls = ... something valid
.....
 a = cls->GetValue();
.....
 
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd). I have lots of inline access functions but only a few are having this problem. The only solution was to remove the "inline" and to move the function's body into a cpp. Am I the only one with this problem ? Or anyone knows any little work around ? Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by c0mas
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd).

That looks suspiciously like the default value that the debug release will set in order to catch uninitialized values. Sounds like you aren't calling a constructor, or else you aren't setting myValue within that constructor. More code would help clarify.

CM

Share this post


Link to post
Share on other sites
Yes, I initialize it and it happends on debug and release too.

In some cases (when I return a pointer) the value is not 0xcdcdcdcd, but a strange value.
Also I've tryed to make the member public and use it directly ... the same result.

One more failed try was to use:

inline void SetGetValue(int &val) {val = myValue;}


It only worked if I used:


static int g_myValue = 0;
.....
g_myValue = myValue; // somwhere in myClass
.....
extern int g_myValue;
.....
int a;
a = g_myValue;

Or if I move the function code inside a .cpp file (and remove the inline modifier).

Im sure that the value is set ok (the debugger shows me the right value, or if a make a trace within "cls" I get the right value). And of course rebuild all does not help.
Also I've tryed to see if it doesn't link with VC6 lib's (I've deleted them and relinked the project) same result.

Share this post


Link to post
Share on other sites
Try pasting a little more consistent code, for all we know you could be housing evil marsians inside those dots.

As the others said, 0xCDCDCDCD most commonly means that the variable has not been initialized, try explicitly setting it first and so on.

Share this post


Link to post
Share on other sites
Well, it's not, unless that's the value you set it to.
Either that or it's not pointing to something that is valid anymore.

Share this post


Link to post
Share on other sites
Uuuuse the Debugger. See if the pointer is changing. If not, put a data breakpoint on mydata and see where it fires.

Share this post


Link to post
Share on other sites
Well, I've checked with the debugger.

cls it's ok and I can call any function in it. More than that, if I enter (with the debugger) in a cls->Function, myValue it's ok.

I've just realized that I have another thing to try: I'll check if the address(or offset from the address of cls) of myValue is the same.

Share this post


Link to post
Share on other sites
That works perfectly fine with me in .NET 2003 so there must be a problem somewhere else in the code...
Like someone said before. If you show more code then it might be easier for us to find your problem.

Share this post


Link to post
Share on other sites
Well and what part of code should I list :) I have about 150 000 lines of code in that project and lots and lots of inline functions and only a fraction of them are making my life a nightmare.

I'm no beginer I just hope someone else had this problem before.

Share this post


Link to post
Share on other sites

This topic is 4480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this