some problem of a.out

K

Kies Lee

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!
 
R

Richard Heathfield

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

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

You're wilcome.
 
S

Shark

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

raju

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
 
F

Flash Gordon

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

Richard Heathfield

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

Kenny McCormack

raju said:


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

Dik T. Winter

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

Keith Thompson

Dik T. Winter said:
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.)
 
C

Chuck F.

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

Kenny McCormack

Keith Thompson said:
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.
 
R

Richard Heathfield

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

Mark McIntyre

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
 
P

pete

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

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top