473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

variable storage

Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.
Jan 7 '08 #1
5 1581
kanalkannan wrote:
Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.
These details are specific to the compiler and it's target system.

Jan 7 '08 #2
On Jan 7, 3:35 pm, kanalkannan <m.selvakan...@gmail.comwrote:
Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.
They're compiler specific and not very important, you can create your
own segment, with any name you like.
Jan 7 '08 #3
Wang Jiaji <ji********@gmail.comwrites:
On Jan 7, 3:35 pm, kanalkannan <m.selvakan...@gmail.comwrote:
>Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.

They're compiler specific
True.
and not very important,
Probably true, though they might be important in some contexts.
you can create your
own segment, with any name you like.
Oh? C has no concept of "segments". Any mechanism for creating your
own would be extremely system-specific.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 7 '08 #4
On Mon, 7 Jan 2008 09:42:10 -0600, Keith Thompson wrote
(in article <87************@kvetch.smov.org>):
Wang Jiaji <ji********@gmail.comwrites:
>you can create your
own segment, with any name you like.

Oh? C has no concept of "segments". Any mechanism for creating your
own would be extremely system-specific.
int segment; /* this is my segment, there are many like it
* but this one is mine.
*/


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Jan 7 '08 #5
On Jan 6, 11:35*pm, kanalkannan <m.selvakan...@gmail.comwrote:
Hi,
* * * * I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.
All auto variables are placed into automatic storage.
All variables allocated with malloc() or calloc() are placed in
allocated storage.
All variables that are static or global have static duration.

Stack and heap do not appear in the standard. Many compilers place
automatic storage on a stack. Many compilers place allocated storage
on a heap. From the C language's perspective, understanding of the
physical location is not necessary to use the memory. There is no
imporant reason that all three types of storage could not be in the
same type of physical structures and general locations.

If you really want to know where something resides, take the address
of it (unless it is already an address) and (after casting to void *)
print the address with a %p format specifier. That will tell you
where the variable is located. Of course, it could be a symbolic
address running in a virtual machine, but that's neither here nor
there. You would get the compiler's view of where the data lives
exactly in any case.
Jan 8 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: bartek | last post by:
Hello, I've been pondering with this for quite some time now, and finally decided to ask here for suggestions. I'm kind of confused, actually... Maybe I'm thinking too much... Brain dump...
3
by: Bryan Parkoff | last post by:
.....I try to reduce un-necessary temporal variables so it can be optimized for best performance. I try to assign only one register storage so two variables can access to only one register storage...
1
by: ravi_shankar | last post by:
I know java,but I am just beginner in C.I have some confusions regarding extern storage specifier and default storage class specifier for a variable when it has file scope that is ,when it is not...
3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
6
by: junw2000 | last post by:
When I define a static variable, where is the memory allocated for the static variable? Thanks. Jack
16
by: John | last post by:
Does the length of my C variable names have any affect, performance-wise, on my final executable program? I mean, once compiled, etc., is there any difference between these two: number = 3; n =...
148
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
10
by: subramanian100in | last post by:
Suppose I declare a global variable int g; in two different files say a.c which has main() and b.c When I compile them to build an executable under gcc in Redhat Linux with the command ...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.