473,545 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable allocated from stack/bss ??

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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??

Nov 29 '06 #1
148 5418
MQ

onkar wrote:
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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??
Local variables are stored on the stack. BSS is used for uninitialized
global or static variables.

Nov 29 '06 #2
MQ said:

<snip>
Local variables are stored on the stack.
C&V please.
BSS is used for uninitialized
global or static variables.
C&V please.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 29 '06 #3
onkar said:
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 ?
The C Standard doesn't require your implementation to have a bss or a stack.
It does require, however, that you provide a proper prototype for printf,
and it also requires that you don't evaluate indeterminately-valued
objects.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 29 '06 #4
onkar wrote:
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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??
The C standard doesn't specify the exact places where variables of
different types are stored. It just specifies their scope,
implementations are free to do whatever they want behind the scenes, as
long as all the necessary semantics are maintained.

Coming to your off-topic question, the short answer is yes, on most
implementations .

Nov 29 '06 #5
onkar wrote:
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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??
Neither 'bss' nor 'stack' have any meaning in C. All we can say is that
'i' is an uninitialized automatic variable, and so has an indeterminate
initial value. If your implementation has some segment of memory
initialized to zero -- and that is by no means a given -- then it may,
or may not, use parts of that for some automatic variables. The
mechanism is completely up to the implementation.

Nov 29 '06 #6
MQ wrote:
onkar wrote:
>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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??

Local variables are stored on the stack. BSS is used for uninitialized
global or static variables.
There is no such requirement for an implementation of the C programming
language. There is, in fact, no requirement for things called 'stack'
or 'BSS' to even exist. Please don't give such foolish and incorrect
'answers'. They only show your limited experience and lack of
qualification to give meaningful answers.
Nov 29 '06 #7
Martin Ambuhl wrote:
onkar wrote:
>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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??


Neither 'bss' nor 'stack' have any meaning in C. All we can say is that
'i' is an uninitialized automatic variable, and so has an indeterminate
initial value. If your implementation has some segment of memory
initialized to zero -- and that is by no means a given -- then it may,
or may not, use parts of that for some automatic variables. The
mechanism is completely up to the implementation.
Translation:

In some weird implementation that could exist somewhere there is no
stack and no bss. Since I want to be pedantic I will generalize then
to say that "The C language dfoesn't require a stack" even if I know
that 99% of all the implementations in work stations today use
exactly those.

Nov 29 '06 #8
onkar wrote:
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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??
Yes, you are right
Nov 29 '06 #9
jacob navia said:
onkar wrote:
>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 ?

I think it is stack,because it prints garbage value; If it were
allocated from bss the default value would be 0
please tell me if I am right or wrong ??

Yes, you are right
Chapter and verse, please.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 29 '06 #10

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

Similar topics

18
33849
by: Jack | last post by:
Thanks.
6
3954
by: junw2000 | last post by:
When I define a static variable, where is the memory allocated for the static variable? Thanks. Jack
53
26333
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global variable? My answer: static variable in function and global variable are allocated in head, and automatic variable is allocated in stack. Right?
0
7473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7406
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7660
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7813
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7431
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5337
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3457
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.