473,467 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

static variable

When I define a static variable, where is the memory allocated for the
static variable?
Thanks.

Jack

Jul 10 '06 #1
6 3937
ju******@gmail.com wrote:
When I define a static variable, where is the memory allocated for the
static variable?
Somewhere in an implementation-defined location.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 10 '06 #2
ju******@gmail.com wrote:
>When I define a static variable, where is the memory allocated for the
static variable?
This is one of the areas were there is no difference between C and
C++. The answers you got when you asked the same question in
comp.lang.c are still valid.
Jul 10 '06 #3

Roberto Waltman wrote:
ju******@gmail.com wrote:
When I define a static variable, where is the memory allocated for the
static variable?

This is one of the areas were there is no difference between C and
C++. The answers you got when you asked the same question in
comp.lang.c are still valid.
I think for a static variable defined out of any functions, i.e., it is
a global variable, it is located in the data segment of the program.
How about a static variable defined within a function? it is a local
variable. Is it located at the stack?

Thanks.

Jul 14 '06 #4
ju******@gmail.com wrote:
Roberto Waltman wrote:
>ju******@gmail.com wrote:
>>When I define a static variable, where is the memory allocated for
the static variable?

This is one of the areas were there is no difference between C and
C++. The answers you got when you asked the same question in
comp.lang.c are still valid.

I think for a static variable defined out of any functions, i.e., it
is a global variable, it is located in the data segment of the
program. How about a static variable defined within a function? it is
a local variable. Is it located at the stack?
There is no such thing in C++ as "data segment" or "stack" (except
std::stack, which is a standard container adaptor). There _is_ the
"free store" where dynamic objects are allocated. We know that static
or automatic objects are not allocated in the "free store", but that's
the extent of the *defined* part.

We also know that the storage for _all_ static objects is reserved
at the program start, function-local static objects included. The
storage is also known to be zero-initialised. *Where* that storage
is located is absolutely implementation- and platform-specific.

If you'd like to talk particulars of object storage implementation
("data segment", "stack", etc.), please do it in a relevant newsgroup,
like one for your OS or compiler.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 14 '06 #5
ju******@gmail.com schrieb:
Roberto Waltman wrote:
>ju******@gmail.com wrote:
>>When I define a static variable, where is the memory allocated for the
static variable?
This is one of the areas were there is no difference between C and
C++. The answers you got when you asked the same question in
comp.lang.c are still valid.

I think for a static variable defined out of any functions, i.e., it is
a global variable, it is located in the data segment of the program.
How about a static variable defined within a function? it is a local
variable. Is it located at the stack?
There are no local or global variables in C or C++.

Variables habe a lifetime and a scope. The lifetime of static variables
is that of the programm.

The C++ standard doesn't talk about data segments or stacks, but the
implementation _can_ choose to put these variables (both "local" and
"global" statics) into the data segment, so that this lifetime is granted.

--
Thomas
Jul 15 '06 #6
Thomas J. Gritzan posted:

There are no local or global variables in C or C++.

When I hear "local variable", I think "variable defined within a function".
--

Frederick Gotham
Jul 15 '06 #7

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

Similar topics

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; } /*...
9
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
5
by: Tom Pearson | last post by:
What is the scope of static variable when programming in ASP.NET? For example I have a control class that uses static callbacks so that another window can pass a list of items to it. The control...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
6
by: Vladislav Kosev | last post by:
I have this strange problem now twice: I am writing this relatevely large web site on 2.0 and I made a static class, which I use for url encoding and deconding (for remapping purposes). This static...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
16
by: RB | last post by:
Hi clever people :-) I've noticed a lot of people stating not to use static variables with ASP.NET, and, as I understand it, the reason is because the variable is shared across user sessions -...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.