Dump program variables

Hi,

Wish if could provide some clues.
How do I dump all the C program variables(global) into say a file with their names and the values. So that when I restart the application again I could use this same file for reinitializing.Is this possible?

Thanks,
Reji

To do this the way you state it is only possible if you use the symbol table, and you do not want to use a debugging tool as part of your program :slight_smile:

You should put all your globals into a struct, and then read and write that struct.

lets say you have a name, and some int, and a float:

int GL_i;
char GL_name[256];
float GL_f;

Change this to:

struct {
	int i;
	char name[256];
	float f;

} GL;

As a rule, if you have lots of globals spread out like in the first example, your program is badly structured.
A global is a potential bug.
For every global, contemplate making it static.
For the structure above, contemplate storing it in a dynamically allocated buffer - you will win big: You can have multiple instances, and your program (or library) will become safer, for a library this may provide reentrancy (each instance has its own data - or you will have to lock it!)

Atle