Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code segment data segment

Status
Not open for further replies.

yogesh77

Programmer
Jul 19, 2001
18
US
friends i asked you about this and after finding
the things manually i conclude

1.all global stored in data segment
2.all locals and func parameteres stored in stack segment
3.function static or otherwise stored in code segment
(it may be called the initialized data segment which may be
thaught of as a part of code segment)

4.all structured constants are a part of symbol table
which inturn is a part of codesegment

a case

char * p="abcd";
p is stored in the stack while "abcd" in the
code segment;

while char ptr[]="abcd"
everything is stored in the stack

static char ptr[]="abcd"
everything stored in the data segment
 
Hello,
This may be right, and this may be wrong, it depends on the C compiler. The C language is machine and compiler independant, and so a compiler-maker may choose to do it in a different way.

greetings, Wouter Dijkslag

 
I am agree with yogesh77. Yes, it is not documented in C standard where the data are stored, but from my experience it is exactly as yogesh77 said. I don't see why somebody would implement it in a different way, for me it looks more fundamental that just "choice of implementation". But I will not give 100% that I am right.
 
Hello,

Very simple, what about computers who have no segments for instance, there are much more computers out there then just PC's :) Wouter Dijkslag

 
I think these are all OS [ any may Complier] dependent, but generally the auto variables are stored in stacks and global and static and arrays [ auto or gloable ] are stored in queues.

You can test this by delaring the some variables within a function, outside a function and declaring some of them as static and by printing the address of them.

eg.

int a, b;
int main()
{
int c, d;
static int i;
char array[4];
/*
print addess of all the variable and address of all the elements in the array */
return 0;
}

You can see the variabls c and d address will be in decreasing oder and the remaining are in increasing order.

Maniraja S
 
As I know On UNIX memory looks like that:
|-program+data-|-Dynamic mem grows ->.. ..<-stack mem grows|
Once I had problem when stack was to big it just corrupted data from dynamic memory. I was surprised that UNIX do not control when dynamic and stack memory overloding each other.
 

LIM, in unix the basic architecture is as i said before
correct me if its wrong

we are given a process area
this area has four parts
1.the code segment which doesnot change
2.the data segment which has two parts
a.initialized data
b.uninitialized
3.stack segment which is at the top of the process area
and grows down(stack ptr shifts downward with func calls
and your temporary variables)

4.the heap which starts where data segment ends and grows
towards the stack

now there are times when stack memory overwrites the heap
and this is a nasty problem ,which we have to control
by letting no memory leak and optimising the function calls
for you will have less no of registers stored

tell me if i am wrong
 
i think you have expained clearly
 
i am sorry the above message was meant for other forum
i am sincerely sorry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top