The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A program to trace execution of another program jiten_hegde High Level Programming 3 1 Week Ago 02:26 AM
How to access the C program variables in shell script bhakti Shell Programming and Scripting 3 07-12-2006 10:41 PM
Passing shell variables to awk program.. Vishnu Shell Programming and Scripting 1 07-17-2004 07:04 AM
Dummie: How do I get variables mid program RichardB UNIX for Dummies Questions & Answers 1 05-06-2002 11:07 AM
help, what is the difference between core dump and panic dump? aileen UNIX for Dummies Questions & Answers 1 06-11-2001 05:08 PM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-17-2002
Registered User
 

Join Date: Aug 2001
Posts: 2
Unhappy 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
Forum Sponsor
  #2 (permalink)  
Old 03-19-2002
Registered User
 

Join Date: Feb 2002
Location: Brabant, Belgium
Posts: 65
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 :-)

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
__________________
PS
All of the above is to be read as '... unless I am wrong'
ENDPS
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0