Shady Programmer
Shady Programmer

Reputation: 824

C - Investigating stack and heap contents program

How would I go about writing a C program that lists ALL the contents of stack and heap including its own variables and mallocations ?

The purpose of it is for me to be able to see what's going on in the memory as I write and test code.

Upvotes: 0

Views: 118

Answers (1)

Bathsheba
Bathsheba

Reputation: 234635

The c standard doesn't explicitly mention a stack or a heap. That, along with the fact that variable and function names are compiled out, means that your task is impossible.

You could build your own compiler which would effectively be a debugging tool. But that would be ridiculous as such a thing would take a long time to build and you'd have to adapt it constantly as the standard evolves. Or you could use the output of a compiler that generates debugging symbols.

Better still, learn to use a good debugger.

Upvotes: 3

Related Questions