Results 1 to 5 of 5

Thread: starting int main(int argc,char *argv[])............

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore,India
    Beans
    982
    Distro
    Ubuntu 10.04 Lucid Lynx

    starting int main(int argc,char *argv[])............

    in linux os,how exactly os knows when c++ object file is kept on main memory?
    is that os triggers a function called "c startup()" routine, then this
    cstartup() invokes main(int argc,char *argv[]).Then where this main function returns?
    i just got to know about it but confused, how actually it happens?
    Abhilash Muthuraj-views
    I always believe that Linux,
    "In a world of no walls or fences, we don't need WINDOWS or GATES"
    New to Ubuntu??

  2. #2
    Join Date
    May 2008
    Location
    UK
    Beans
    1,450
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: starting int main(int argc,char *argv[])............

    What happens is that Linux has a standard format for all executable files. The file will include things such as indicators of the entry point of the programm.

    The C compiler and linker will build one of these standard executable files, and will include the indicators to point into the file where the main() function has been translated.

    When you try to run the executable, the linux OS will load the executable file, and look for the entry point indicators, and execute the relevant part of the executable file. So long as we are talking about a fully compiled programm, the OS has no knowledge of which actual language was used to create the program.
    With interpreted or partial compiled programms (for instance Python, Java, perl, Shell Scrips, and many others), then the OS will execute a Interpreter or VM first (which will be a fully compiled application).

    To my knowledge all Linux full executables (whether they be written in C or another compiled language) all deal with the command line in the same way, i.e. all the arguments are placed on the start before the executable's entry point is called.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore,India
    Beans
    982
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: starting int main(int argc,char *argv[])............

    yes sure, what you told was true, when an executable is placed,
    everything gets converted to machine level program format, use of registers it just executes.
    do linux OS has any function like "cstartup" function to know where main() function is, this is highlight of my question..........
    Abhilash Muthuraj-views
    I always believe that Linux,
    "In a world of no walls or fences, we don't need WINDOWS or GATES"
    New to Ubuntu??

  4. #4
    Join Date
    Apr 2005
    Beans
    849

    Re: starting int main(int argc,char *argv[])............

    It should depend on the underlaying platform.

    Most unixes today use the elf format.
    http://en.wikipedia.org/wiki/Executa...inkable_Format

    You should read up on this if you are interested in this very low level or highlevel stuff. Depending on your viewpoint


    Most programmers, don't care about this aspect of software development.
    And I don't think you would need to know it, unless your are doing system programming.
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore,India
    Beans
    982
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: starting int main(int argc,char *argv[])............

    ya even i was not intrested untill in class, my teacher highlighted about this, i googled but it din't really show what i wanted now it's fine.......
    Abhilash Muthuraj-views
    I always believe that Linux,
    "In a world of no walls or fences, we don't need WINDOWS or GATES"
    New to Ubuntu??

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •