| Topic: |
DEVELOP > C |
| User: |
"Kies Lee" |
| Date: |
15 Jan 2006 10:49:25 PM |
| Object: |
some problem of a.out |
I am a beginner in c programming. Now I have a question:
[code]
main() {
int i = 3;
int j;
}
Compile it to a.out.
Where the 'i','j' be in the a.out, the bss section, date section, or in
the stack?
Think you!
.
|
|
| User: "Richard Heathfield" |
|
| Title: Re: some problem of a.out |
15 Jan 2006 10:54:38 PM |
|
|
Kies Lee said:
I am a beginner in c programming. Now I have a question:
[code]
main() {
int i = 3;
int j;
}
Compile it to a.out.
Where the 'i','j' be in the a.out, the bss section, date section, or in
the stack?
There's no requirement for the compiler to create the objects anywhere at
all, because not doing so will not change the output of the program.
In any case, the answer to your question depends entirely on the
implementation. C compilers are not required to employ a bss section, a
date section, a data section, or a stack.
Think you!
You're wilcome.
--
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)
.
|
|
|
| User: "Shark" |
|
| Title: Re: some problem of a.out |
15 Jan 2006 11:25:44 PM |
|
|
There's no requirement for the compiler to create the objects anywhere at
all, because not doing so will not change the output of the program.
but most likely his code will be optimized to an empty main() returning
0
So i, or j exist nowhere. Besides, a.out has its own file format which
determines where things will be "unloaded" in memory during execution.
If you compiled to a .EXE file on dos, the places where your
constants/variables reside will be determined by your OS and your file
format.
Generally if you declare and define your variables like you did, they
reside on the stack (or auto store), which has different meaning
depending on your compiler and OS etc.
Therefore your question lies on the border of assembly and something
"else" (where "else" is definitely not standard C!!!) so an assembly
newsgroup will be better suited to give you pointers on how this works.
.
|
|
|
|
| User: "Default User" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 12:04:00 AM |
|
|
Richard Heathfield wrote:
Kies Lee said:
Think you!
You're wilcome.
No, that was him telling you to put your brain in gear, "Think, you!"
He left out a comma.
Brian
--
If televison's a babysitter, the Internet is a drunk librarian who
won't shut up.
-- Dorothy Gambrell (http://catandgirl.com)
.
|
|
|
|
|
| User: "pete" |
|
| Title: Re: some problem of a.out |
17 Jan 2006 09:40:27 AM |
|
|
Kies Lee wrote:
I am a beginner in c programming. Now I have a question:
[code]
main() {
int i = 3;
int j;
}
Compile it to a.out.
Where the 'i','j' be in the a.out, the bss section,
date section, or in the stack?
The objects i and j themselves, won't be in a.out.
The instructions for creating the objects i and j,
will be in a.out.
--
pete
.
|
|
|
|
| User: "raju" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 01:30:05 AM |
|
|
see every thing i.e is auto variables stored in stack when a fuction
called , if you made it as static int i=3;
this will be stored in initialized data segment.
if you say static int j;
i,e uninitialized data segment and at runtime this will be assigned
to zero; samething with uninitiolized variables...
this will be stored in bss;
and initialized global variable get stored in datasegments
ok
take acre
.
|
|
|
| User: "Richard Heathfield" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 05:44:44 AM |
|
|
raju said:
see every thing i.e is auto variables stored in stack
Chapter and verse, please. Where does the Standard guarantee that auto
variables are stored in a stack?
when a fuction
called , if you made it as static int i=3;
this will be stored in initialized data segment.
Chapter and verse, please.
if you say static int j;
i,e uninitialized data segment
Chapter and verse, please.
and at runtime this will be assigned
to zero; samething with uninitiolized variables...
this will be stored in bss;
Chapter and verse, please.
and initialized global variable get stored in datasegments
Chapter and verse, please.
--
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)
.
|
|
|
| User: "Kenny McCormack" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 08:44:41 AM |
|
|
In article <dqg0vc$kgg$2@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <invalid@invalid.invalid> wrote:
raju said:
see every thing i.e is auto variables stored in stack
Chapter and verse, please. Where does the Standard guarantee that auto
variables are stored in a stack?
(etc)
You're wasting your breath, and I will tell you why. The morons who go on
about stacks and stuff here have certainly never heard of the Standard.
And I doubt they'd catch the meaning of your biblical references.
.
|
|
|
| User: "Dik T. Winter" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 06:08:25 PM |
|
|
In article <dqgbfi$13t$1@yin.interaccess.com> writes:
In article <dqg0vc$kgg$2@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <invalid@invalid.invalid> wrote:
raju said:
see every thing i.e is auto variables stored in stack
Chapter and verse, please. Where does the Standard guarantee that auto
variables are stored in a stack?
You're wasting your breath, and I will tell you why. The morons who go on
about stacks and stuff here have certainly never heard of the Standard.
And I doubt they'd catch the meaning of your biblical references.
It is (if I remember right) not e biblical reference, but a reference
to this newsgroup: Dan Pop.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
.
|
|
|
| User: "Keith Thompson" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 06:39:15 PM |
|
|
"Dik T. Winter" <Dik.Winter@cwi.nl> writes:
In article <dqgbfi$13t$1@yin.interaccess.com> writes:
In article <dqg0vc$kgg$2@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <invalid@invalid.invalid> wrote:
raju said:
see every thing i.e is auto variables stored in stack
Chapter and verse, please. Where does the Standard guarantee that auto
variables are stored in a stack?
You're wasting your breath, and I will tell you why. The morons who go on
about stacks and stuff here have certainly never heard of the Standard.
And I doubt they'd catch the meaning of your biblical references.
It is (if I remember right) not e biblical reference, but a reference
to this newsgroup: Dan Pop.
I'm reasonably sure the phrase "chapter and verse" originally referred
(and still does) to biblical references. The Bible is divided into
"books", each books is divided into chapters, each chapter is divided
into verses. "John 3:16", for example, refers to the book of John,
chapter 3, verse 16.
The extension of the phrase to section/paragraph references in the C
standard is commonplace and fairly obvious. According to the Google
archives, the earliest use of the phrase in comp.lang.c was by Henry
Spencer on December 4, 1986 (referring to K&R1, which was the closest
thing we had to a standard at the time).
(Kenny is wrong as usual.)
--
Keith Thompson (The_Other_Keith) <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.
.
|
|
|
| User: "Kenny McCormack" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 07:52:08 PM |
|
|
In article <lnfynnu1qk.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
....
I'm reasonably sure the phrase "chapter and verse" originally referred
(and still does) to biblical references. The Bible is divided into
"books", each books is divided into chapters, each chapter is divided
into verses. "John 3:16", for example, refers to the book of John,
chapter 3, verse 16.
Yes, very true.
The extension of the phrase to section/paragraph references in the C
standard is commonplace and fairly obvious. According to the Google
archives, the earliest use of the phrase in comp.lang.c was by Henry
Spencer on December 4, 1986 (referring to K&R1, which was the closest
thing we had to a standard at the time).
Yes, very true.
(Kenny is wrong as usual.)
ITYM:
"Dik T. Winter" is wrong thie time. But we all have our off-days.
HTH, HAND.
.
|
|
|
|
| User: "Mark McIntyre" |
|
| Title: Re: some problem of a.out |
17 Jan 2006 04:34:25 AM |
|
|
On Tue, 17 Jan 2006 00:39:15 GMT, in comp.lang.c , Keith Thompson
<kst-u@mib.org> wrote:
I'm reasonably sure the phrase "chapter and verse" originally referred
(and still does) to biblical references.
Sure did. But, trolls commnets notwithstanding, as I'm sure youre
aware C&V is common english usage for a precise reference to an
accepted text. Its use is far from restricted to CLC - see meaning 1
below for example.
http://www.thefreedictionary.com/chapter+and+verse
(Kenny is wrong as usual.)
Return to type then...
Mark McIntyre
--
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.
|
|
|
|
|
| User: "Richard Heathfield" |
|
| Title: Re: some problem of a.out |
17 Jan 2006 01:05:14 AM |
|
|
Dik T. Winter said:
["Chapter and verse"] is (if I remember right) not e biblical reference,
Clearly its origins are Biblical (or rather, suprabiblical, since chapter
and verse divisions were not added to the Bible until roughly 1200AD +/- a
century or so), but equally clearly it is a widely understood expression. I
am quite certain (although I cannot prove) that I was familiar with the
expression in its wider sense long before I got onto the Net.
--
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)
.
|
|
|
|
| User: "Chuck F. " |
|
| Title: Re: some problem of a.out |
16 Jan 2006 07:38:20 PM |
|
|
Dik T. Winter wrote:
.... snip ...
It is (if I remember right) not e biblical reference, but a
reference to this newsgroup: Dan Pop.
Speaking of whom, has anyone heard anything about him in the past
year or so? We miss his knowledge and diplomatic tone. (1/2 of
that is sarcastic).
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
.
|
|
|
|
|
|
|
| User: "Flash Gordon" |
|
| Title: Re: some problem of a.out |
16 Jan 2006 05:36:56 AM |
|
|
raju wrote:
Please provide context when replying. People might not have seen the
article you are replying to. For details on how to do this using Google
and other useful advice please see http://cfaj.freeshell.org/google/
see every thing i.e is auto variables stored in stack when a fuction
called ,
Wrong for a number of reasons. The C standard does not mandate the
existence of a stack and even on real implementation with a stack auto
variables are often stored only in registers if the compiler can get
away with it because that is more efficient.
if you made it as static int i=3;
this will be stored in initialized data segment.
Again, there may not be an initialised data segment. I've worked on real
systems without such a thing although they did (as the standard
mandates) initialise variables with static storage duration.
if you say static int j;
i,e uninitialized data segment and at runtime this will be assigned
to zero; samething with uninitiolized variables...
this will be stored in bss;
Again, not all systems have a bss section. However, you are correct that
the variables will be initialised to 0.
and initialized global variable get stored in datasegments
Again, there is no guarantee there is such a thing as a data segment.
Please don't assume that all the world is using the same system as you
since there are vast numbers of people using completely different
systems with different capabilities and terminology. Here we deal with
standard C not the specifics of your (or anyone else's) specific system.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
|
|
|
|
|

|
Related Articles |
|
|