some problem of a.out

Discussion in 'C Programming' started by Kies Lee, Jan 16, 2006.

  1. Kies Lee

    Kies Lee Guest

    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!
     
    Kies Lee, Jan 16, 2006
    #1
    1. Advertising

  2. 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?[/color]
    
    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.
    [color=blue]
    > Think you![/color]
    
    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)
     
    Richard Heathfield, Jan 16, 2006
    #2
    1. Advertising

  3. Kies Lee

    Shark Guest

    > 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.
     
    Shark, Jan 16, 2006
    #3
  4. Kies Lee

    Default User Guest

    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)
     
    Default User, Jan 16, 2006
    #4
  5. Kies Lee

    raju Guest

    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
     
    raju, Jan 16, 2006
    #5
  6. Kies Lee

    Flash Gordon Guest

    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.
     
    Flash Gordon, Jan 16, 2006
    #6
  7. 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)
     
    Richard Heathfield, Jan 16, 2006
    #7
  8. In article <dqg0vc$kgg$-infra.bt.com>,
    Richard Heathfield <> 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.
     
    Kenny McCormack, Jan 16, 2006
    #8
  9. In article <dqgbfi$13t$> writes:
    > In article <dqg0vc$kgg$-infra.bt.com>,
    > Richard Heathfield <> 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/
     
    Dik T. Winter, Jan 17, 2006
    #9
  10. "Dik T. Winter" <> writes:
    > In article <dqgbfi$13t$> writes:
    > > In article <dqg0vc$kgg$-infra.bt.com>,
    > > Richard Heathfield <> 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.
     
    Keith Thompson, Jan 17, 2006
    #10
  11. Kies Lee

    Chuck F. Guest

    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/>
     
    Chuck F., Jan 17, 2006
    #11
  12. In article <>,
    Keith Thompson <> 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.
     
    Kenny McCormack, Jan 17, 2006
    #12
  13. 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)
     
    Richard Heathfield, Jan 17, 2006
    #13
  14. On Tue, 17 Jan 2006 00:39:15 GMT, in comp.lang.c , Keith Thompson
    <> 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 =----
     
    Mark McIntyre, Jan 17, 2006
    #14
  15. Kies Lee

    pete Guest

    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?[/color]
    
    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
     
    pete, Jan 17, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    707
    Guest
    Feb 25, 2004
  2. Eric
    Replies:
    2
    Views:
    1,562
    Tommy
    Feb 13, 2004
  3. ad
    Replies:
    2
    Views:
    746
  4. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    567
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  5. Replies:
    3
    Views:
    241
Loading...

Share This Page