473,396 Members | 2,111 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,396 software developers and data experts.

where variables are stored?

Neo
Where does global, static, local, register variables, free memory and C
Program instructions get stored?

-Neo
Nov 14 '05 #1
11 7280

"Neo" <ti***************@yahoo.com> wrote in message
news:34*************@individual.net...
Where does global, static, local, register variables, free memory and C
Program instructions get stored?


Depends largely on your compiler/OS.

Locals are usually stored on stack or registers, global initialized data in
some '.data' segment, uninitialized data in the '.bss' segment. But that's a
mere "grosso modo" answer, since there is no generally valid one.

Your compiler may store it in different segments, but the idea will be
pretty much the same.
Nov 14 '05 #2
Neo wrote:

Where does global, static, local, register variables, free memory
and C Program instructions get stored?


It doesn't matter, so long as those entities behave as specified in
the standard. Elves can scratch notes on little bitty pieces of
paper and pass them to other elves for reading, as far as you know.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #3
<posted & mailed>

Neo wrote:
Where does global, static, local, register variables, free memory and C
Program instructions get stored?
That's at the disgression of the compiler / operating environment. C doesn't
require you to need to know that.


-Neo


--
Remove '.nospam' from e-mail address to reply by e-mail
Nov 14 '05 #4
> Elves can scratch notes on little bitty pieces of
paper and pass them to other elves for reading


Little known fact: the Elvish tongue associated this implementation
technique (known as the "Executable and Linking Format" by those who
wish to disguise its true etymology) is actually fairly common.
--
Gregory K. Johnson

Nov 14 '05 #5
Neo wrote:
Where does global, static, local, register variables, free memory and C
Program instructions get stored?

-Neo


Variables, locations that can be modified, must be
stored somewhere where they can be modified: harddrive,
RAM, at a friend's house.

Constants can be placed at locations that are either
read-only or read/write, such as CDROMs, PROMS, RAM,
etc.

The exact location is determined by your compiler,
operating system and platform.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #6
Neo wrote:
Where does global, static, local, register variables, free memory
and [machine] instructions get stored?


It is implementation dependent.
In the *typical implementation*,
you can think of *virtual memory* (vm) as a sequence of addresses

00000000 top
00000001
00000002
Nov 14 '05 #7

"Neo" <ti***************@yahoo.com> wrote in message
news:34*************@individual.net...
Where does global, static, local, register variables, free memory and C
Program instructions get stored?


Somewhere. The language does not specify this.

However, qualifying a declaration with 'register'
comprises a *request* for the compiler to store
an object in a register (in the interest of
'optimization'). But this request need not be
honored (and is rarely needed, since a good compiler
is typically much better at optimization that a mere human).

-Mike
Nov 14 '05 #8
"Mike Wahler" <mk******@mkwahler.net> writes:
"Neo" <ti***************@yahoo.com> wrote in message
news:34*************@individual.net...
Where does global, static, local, register variables, free memory and C
Program instructions get stored?


Somewhere. The language does not specify this.

However, qualifying a declaration with 'register'
comprises a *request* for the compiler to store
an object in a register (in the interest of
'optimization'). But this request need not be
honored (and is rarely needed, since a good compiler
is typically much better at optimization that a mere human).


The standard doesn't even suggest that it be stored in a register
(though as the word implies that, or ignoring it, is probably the most
common behavior). The actual wording (C99 6.7.1p4) is:

A declaration of an identifier for an object with storage-class
specifier register suggests that access to the object be as fast
as possible. The extent to which such suggestions are effective is
implementation-defined.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #9
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> wrote:
Where does global, static, local, register variables, free memory
and C Program instructions get stored?
It doesn't matter, so long as those entities behave as specified in
the standard.
However, the standard is motivated by the usual implementations of
the various kinds of memory. Why would it bother to prevent you
accessing variables after function return if it didn't intend that
they be put on a stack? Why would register variables be so-called
if there were no implication that they might go in registers?

Like most specifications, the C standard is much easier to understand
if you know the motivation for it, and:
Elves can scratch notes on little bitty pieces of
paper and pass them to other elves for reading, as far as you know.


.... is obviously not what the standardizers had in mind.

-- Richard
Nov 14 '05 #10

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:cs**********@pc-news.cogsci.ed.ac.uk...
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> wrote:
Where does global, static, local, register variables, free memory
and C Program instructions get stored?

It doesn't matter, so long as those entities behave as specified in
the standard.


However, the standard is motivated by the usual implementations of
the various kinds of memory. Why would it bother to prevent you
accessing variables after function return if it didn't intend that
they be put on a stack? Why would register variables be so-called
if there were no implication that they might go in registers?

Like most specifications, the C standard is much easier to understand
if you know the motivation for it, and:
Elves can scratch notes on little bitty pieces of
paper and pass them to other elves for reading, as far as you know.


... is obviously not what the standardizers had in mind.


IMO what they had in mind was to keep these things abstract,
and to let implementations define the actual mechanics,
so that they can best take advantage of the host platform
(this includes implementation designs which have yet to be
concieved).

-Mike
Nov 14 '05 #11
Mike Wahler wrote:
Richard Tobin wrote:
CBFalconer wrote:
Where does global, static, local, register variables, free memory
and C Program instructions get stored?

It doesn't matter,
so long as those entities behave as specified in the standard.


However, the standard is motivated by the usual implementations of
the various kinds of memory. Why would it bother to prevent you
accessing variables after function return if it didn't intend that
they be put on a stack? Why would register variables be so-called
if there were no implication that they might go in registers?

Like most specifications,
the C standard is much easier to understand
if you know the motivation for it, and:
Elves can scratch notes on little bitty pieces of
paper and pass them to other elves for reading, as far as you know.


... is obviously not what the standardizers had in mind.


IMO what they had in mind was to keep these things abstract,
and to let implementations define the actual mechanics,
so that they can best take advantage of the host platform
(this includes implementation designs
which have yet to be concieved).


That is correct.
But "the standardizers" must also prove that
an implementation of those abstractions is feasible.
They must be able to describe a "typical implementation".

The typical implementation is also a pedagogical tool
that instructors can use to demystify the function of compilers
and comfort skeptical students of the C programming language.
In this case, the typical implementation need not be
the usual implementation or even an actual implementation
but merely a plausible implementation that can demonstrate
to the student that some implementation is possible.
Nov 14 '05 #12

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

Similar topics

6
by: Shaun Stuart | last post by:
I've got a webpage that calls some stored procedures with input variables. The procedures return recordsets and also some output variables. We're trying to get the values of the output variables....
17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
8
by: VJ | last post by:
Hi, I apologize if this question has been asked many times on the group! I am new to programming, I know that there are three section in address space- one for code, one for stack, and the...
9
by: thomson | last post by:
Hi all, Would you please explain me where will be the heap stored if it is declared inside the Class, As class is a reference type, so it gets stored on the heap, but struct is a value...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
7
by: DC Gringo | last post by:
I was under the impression that when I create session variables such as session("myVar1"), they get stored on the client in a cookie. When I look in my Temporary Internet Files directory for the...
18
by: Jack | last post by:
Thanks.
7
by: kr | last post by:
Hi All, Suppose I consider a sample program as given below:- #include<stdio.h> #include<stdlib.h> int i; int main() { char *test(int i); char *tmp = NULL;
8
by: rashmiharitas | last post by:
where are statics variables stored? static variables and static methods can be used without creation of objects so in which part of memory is static stored plz help me
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.