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 (Text):

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

  2. Kies Lee said:
     
    Richard Heathfield, Jan 16, 2006
    #2
    1. Advertisements

  3. Kies Lee

    Shark Guest

    There's no requirement for the compiler to create the objects anywhere at
    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

    No, that was him telling you to put your brain in gear, "Think, you!"
    He left out a comma.



    Brian
     
    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/
    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.
    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.
    Again, not all systems have a bss section. However, you are correct that
    the variables will be initialised to 0.
    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, Jan 16, 2006
    #6
  7. raju said:
    Chapter and verse, please. Where does the Standard guarantee that auto
    variables are stored in a stack?
    Chapter and verse, please.
    Chapter and verse, please.
    Chapter and verse, please.
    Chapter and verse, please.
     
    Richard Heathfield, Jan 16, 2006
    #7
  8. (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. It is (if I remember right) not e biblical reference, but a reference
    to this newsgroup: Dan Pop.
     
    Dik T. Winter, Jan 17, 2006
    #9
  10. 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, Jan 17, 2006
    #10
  11. Kies Lee

    Chuck F. Guest

    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. Yes, very true.
    Yes, very true.
    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:
    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, Jan 17, 2006
    #13
  14. 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
    Return to type then...
    Mark McIntyre
     
    Mark McIntyre, Jan 17, 2006
    #14
  15. Kies Lee

    pete Guest

     
    pete, Jan 17, 2006
    #15
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.