By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

C variable Storage

P: n/a
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

Thanks
Santosh

Oct 3 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a
Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.
When, oh when, will these "Please do the work for me" questions stop coming
in?

<preaching to the choir>
Oct 3 '06 #2

P: n/a
Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

Thanks
Santosh
This is easy to do:

1) OPEN YOUR TEXT BOOK
2) READ IT!!!!
3) ANSWER THE EXERCISES.

Oct 3 '06 #3

P: n/a

Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

Thanks
Santosh
Maybe the book "Computer Systems: A Programmer's Perspective" is
helpful for you. ;-p

Oct 3 '06 #4

P: n/a
jacob navia wrote:
>
Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

This is easy to do:

1) OPEN YOUR TEXT BOOK
2) READ IT!!!!
3) ANSWER THE EXERCISES.
Actually, isn't the answer "it's all implementation dependant"?
AFAIK (and I've been wrong before), the standard doesn't impose
any limits on how/where/why "variables are stored". The system
could, if the implementor so chooses, group all variables of the
same type together and sort them alphabetically.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Oct 3 '06 #5

P: n/a
Kenneth Brody said:
jacob navia wrote:
>Santy wrote:
I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.
[...]
This is easy to do:

1) OPEN YOUR TEXT BOOK
2) READ IT!!!!
3) ANSWER THE EXERCISES.

Actually, isn't the answer "it's all implementation dependant"?
Yes, any book that answers these questions in some more specific way than
that is unlikely to be a very good C book. (It's not impossible, just very
unlikely.) And there may not be a textbook available that gives such
architectural details for the OP's platform (which was not stated). So
"open your text book" is a bit of a silly answer.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 3 '06 #6

P: n/a
but still there are some methods that might be there
as in interviews they ask about the things as:
---- where the static varibles are stored ?
---- how the execution of the C program ?
etc?

so how can i answer them ,please help to give me the low level details
of the C programming.

Thanks
Santosh

Richard Heathfield wrote:
Kenneth Brody said:
jacob navia wrote:
Santy wrote:
I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.
[...]
This is easy to do:

1) OPEN YOUR TEXT BOOK
2) READ IT!!!!
3) ANSWER THE EXERCISES.
Actually, isn't the answer "it's all implementation dependant"?

Yes, any book that answers these questions in some more specific way than
that is unlikely to be a very good C book. (It's not impossible, just very
unlikely.) And there may not be a textbook available that gives such
architectural details for the OP's platform (which was not stated). So
"open your text book" is a bit of a silly answer.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 4 '06 #7

P: n/a
Santy said:
but still there are some methods that might be there
as in interviews they ask about the things as:
---- where the static varibles are stored ?
If I were asked that in an interview, I'd say: "It depends on the computer
and the compiler, and nobody can be expected to be an expert on all
architectures. But it would be easy enough to find out, for a given system,
by consulting its documentation."
---- how the execution of the C program ?
I can't even begin to interpret that as a question. Sorry.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 4 '06 #8

P: n/a

Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

Thanks
Santosh
Hi Santhosh

Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html

Thanks
Kishore

Oct 4 '06 #9

P: n/a

Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area

The C standard doesnt say much about this, it just requests that static
and global variables hold their values.

The compiler is free to put the variables wherever it wants-- sometimes
in specific fixed locations in memory, sometimes in registers,
sometimes in temporary areas on the stack.
For that matter, it could just as well allocate them in a database, in
a file, in virtual memory, as symbols in the program's environment, or
most anywhere.

One way to learn the nitty-gritty is to compile a small C program and
specify the "-S" option, or whatever options writes out an assembly
language source file. The either learn asm, or find a book or person
that understands it. You should see places in the asm code where
global variables are defined, where local variables are accessed as
offsets from the stack or base pointer, and where some inner-loop
variables are held in registers. Can be a fascinating journey.

Oct 4 '06 #10

P: n/a
Santy wrote:
>
but still there are some methods that might be there
as in interviews they ask about the things as:
---- where the static varibles are stored ?
In some place that will be accessible for the duration of the
execution of the program. Where, exactly, that is, is entirely
up to the system (a combination of what the hardware can do, what
the O/S will allow a program to do, and what the implementor of
the C envinronment chose to do).
---- how the execution of the C program ?
I don't understand what you're asking, but there's really nothing
to be said beyond "the O/S and runtime library startup code do
some magic, and then call main(), and when main() returns, do some
more magic". (Well, you could get into "exit()", "abort()" and
things like Unix "segmentation violations" if you wanted to get
even further into the mess.)
etc?

so how can i answer them ,please help to give me the low level details
of the C programming.
[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Oct 4 '06 #11

P: n/a
Hi Kishore,
Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.

thank you very much.

Thanks
Santosh

klakkamr wrote:
Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.

Thanks
Santosh

Hi Santhosh

Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html

Thanks
Kishore
Oct 5 '06 #12

P: n/a
"klakkamr" <ki*******@gmail.comwrote:
Santy wrote:
I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area according to their Storage classes and all.

also how the memory mgmt is done while execution.
Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html
Or perhaps not, since it is highly (and explicitly, though from the
looks of it only by accident) UNIX-specific, and not very well written
either.

Richard
Oct 5 '06 #13

P: n/a
Santy wrote:
klakkamr wrote:
Santy wrote:
Hello Friends,
>
I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.
>
also how the memory mgmt is done while execution.
>
if their is any book which can be refered.
Hi Santhosh

Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html

Hi Kishore,
Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.

thank you very much.
Just wanted to let you know that top-posting, (which I have taken the
liberty to fix in this instance), and SMS style abbreviations are not
well recieved, (and for good reasons, I might add), in this group. To
rid yourself of this blight of character read the information at the
following URLs.

<http://cfaj.freeshell.org/google/>
<http://www.safalra.com/special/googlegroupsreply/>

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://en.wikipedia.org/wiki/USENET>
<http://en.wikipedia.org/wiki/Netiquette>

Oct 5 '06 #14

P: n/a
(Top-posting corrected.)

Santy wrote:
klakkamr wrote:
Santy wrote:
Hello Friends,
>
I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.
>
also how the memory mgmt is done while execution.
>
if their is any book which can be refered.
Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html

Hi Kishore,
Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.

thank you very much.
Well, it may include "imp information" to you, but you have to
realize that the page does _not_ explain where "C" will put
things, but rather how the particular C compiler used at the
Computer Science department at UMass Lowell puts things.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Oct 5 '06 #15

P: n/a
In article <45***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.netwrote:
>Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.
>Well, it may include "imp information" to you, but you have to
realize that the page does _not_ explain where "C" will put
things, but rather how the particular C compiler used at the
Computer Science department at UMass Lowell puts things.
Indeed, many modern compilers don't use imps at all.

-- Richard
Oct 5 '06 #16

P: n/a
In article <eg**********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>In article <45***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.netwrote:
>>Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.
>>Well, it may include "imp information" to you, but you have to
realize that the page does _not_ explain where "C" will put
things, but rather how the particular C compiler used at the
Computer Science department at UMass Lowell puts things.

Indeed, many modern compilers don't use imps at all.

-- Richard
Certainly not in pairs events.

Oct 6 '06 #17

P: n/a
santosh wrote:
Santy wrote:
klakkamr wrote:
Santy wrote:
Hello Friends,

I want to know some details regarding the C programming.
When we run the program exe then how the variable are stored in the
memory area
according to their Storage classes and all.

also how the memory mgmt is done while execution.

if their is any book which can be refered.
>
Hi Santhosh
>
Hope the following link will be useful.
http://www.cs.uml.edu/~kfawcett/cs1/Stack_add.c.html
Hi Kishore,
Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.

thank you very much.
Apart from the books and URLs it is a good practise to see-it-yourself
approach. There are many code/programming related tools which can help.
I will give you a short info, if you are enthusiastic then go ahead and
learn them.

Debuggers:
In Linux/Linux like systems you will have gdb (gnu debugger)
In Windows one can use MVC++

Tools related to obj/exe files
nm - it lists symbols from object files.
strace - traces system calls and signals

Compiler related tools:
gcc -E <source name gives you the output of arcane C
preprocessor
gcc -S <source name gives the generated code in assembly
>
Just wanted to let you know that top-posting, (which I have taken the
liberty to fix in this instance), and SMS style abbreviations are not
well recieved, (and for good reasons, I might add), in this group. To
rid yourself of this blight of character read the information at the
following URLs.

<http://cfaj.freeshell.org/google/>
<http://www.safalra.com/special/googlegroupsreply/>

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://en.wikipedia.org/wiki/USENET>
<http://en.wikipedia.org/wiki/Netiquette>
Oct 6 '06 #18

P: n/a
Richard Tobin wrote:
>
In article <45***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.netwrote:
Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.
Well, it may include "imp information" to you, but you have to
realize that the page does _not_ explain where "C" will put
things, but rather how the particular C compiler used at the
Computer Science department at UMass Lowell puts things.

Indeed, many modern compilers don't use imps at all.
In fact, many have replaced each imp with an elf.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Oct 6 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.