-2

I keep getting the following error during the run of my program:

First-chance exception at 0xCCCCCCCC in Project1.exe: 0xC0000005: Access violation executing location 0xCCCCCCCC.

I think it has something to do with the specific address being invalid or empty? I just need to know how I can find what is contained in 0xCCCCCCCC and what variable is taking that place.

I have too many variables to go throw and find each address so I am trying to find a way to go "backwards" from address to variable rather than what you would do with "%p" with a variable to an address.

Thanks.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
user3397612
  • 91
  • 1
  • 7

3 Answers3

4

0xCCCCCCCC is a magic number used by the Debug version of the Microsoft C Runtime and code generated by the Microsoft C compiler for debug builds.

There are other magic numbers as well.

0xCCCCCCCC is used to mark uninitialized stack memory. You would see an exception like you've shown if you do something like this:

void test(void)
{
    void *p;
    memset(p, 0, 100);    // Pointer p is used uninitialized
}

You should pay attention to the warnings emitted by your compiler. There's a good chance it's warning you that you're doing something stupid, but you're ignoring that warning.

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
0

0xCCCCCCCC is not a valid memory location at all, that's why you got an access violation. There's nothing there that you can read, or this error would not have occurred in this way.

What you have is an invalid/dangling/wild/uninitialized pointer. To track that down you'll need a debugger or a tool like valgrind (if you're on Linux, other tools exist for other platforms).

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
0

You can't. In C, all information regarding how variables are declared and how memory is initialized doesn't exist at runtime. "Variables" are a compile-time concept that doesn't translate into the generated assembly very well. You'll need a debugger to step through your code one step at a time and see where things go wrong.

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79