C variable Storage

S

Santy

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
 
C

Christopher Layne

Santy said:
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>
 
J

jacob navia

Santy said:
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.
 
K

Kenneth Brody

jacob said:
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:[email protected]>
 
C

Cong Wang

Santy said:
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
 
R

Richard Heathfield

Kenneth Brody said:
jacob said:
Santy said:
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>
 
S

Santy

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 said:
Kenneth Brody said:
jacob said:
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)
 
R

Richard Heathfield

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.
 
K

Kenneth Brody

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 ?

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:[email protected]>
 
K

klakkamr

Santy said:
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
 
A

Ancient_Hacker

Santy said:
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.
 
S

Santy

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
 
S

santosh

Santy said:
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>
 
K

Kenneth Brody

(Top-posting corrected.)
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:[email protected]>
 
R

Richard Tobin

Yes this link contains some imp information i need.
if u know such links regarding C C++ ,please do forward me.
[/QUOTE]
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
 
K

Kenny McCormack

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[/QUOTE]

Certainly not in pairs events.
 
Q

quarkLore

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
 
K

Kenneth Brody

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.[/QUOTE]

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:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top