Welcome, Guest. Please login or register.

Author Topic: Odd programming question  (Read 6580 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Odd programming question
« on: March 10, 2008, 10:58:50 AM »
Quote

trekiej wrote:
Outside of header files and libraries, when does OS specific information get added?
When I run a programm, how does  the OS allocate memory and give control to the application and the application give it back.
The OS gives the application access to resources, how does it know what to give?
Source > Object > linking > Binary


Your compiler implementation provides the standard C library (and maybe C++ library, etc too). The interfaces to these libraries, eg stdlib.h, stdio.h etc should provide the same set of functions across different platforms. They may vary depending on compiler age/version and even on platform but for example, stdio.h should provide you with the printf() function, for example, pretty much everywhere you go.

The implementation of these libraries, however is basically up to the compiler and the platform, as long as they provide the functionality advertised in the headers.

Your platform provides basic IO, memory management etc that the C library implementation for that platform uses. Essentially therefore, you can view your compiler's C standard library implementation as an abstraction layer to OS specific features.

When your code is linked, as well as the platform specific implementation of the C standard library, platform specific startup code is added that ensures your various IO streams etc. are available and ultimately invokes main() in your application.

Having said all this, you don't need to worry about any of it. As Piru stated, "It Just Works". How it works is really only of academic interest.
int p; // A