Click here to Skip to main content
15,902,445 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
As i know Windows operating system used the assembly language to interact with the hardwares.
When they did this,they could use c,c++ or any other language to the rest work.

As i know C++ header files(In C++ standard library) actually call the windows api for the implementaion.

So where are header files located? Are them installed by compilers ? or they come with the operating systems?

What keyword or code do the header files use to interact with the sutable api(for example std::cout on windows,calls a function in a dll file and in linux an other)?

For example is iostream.h different on linux from windows?

And how that how they find suitable libraries?

And my last question is that,how libraries interact with assembly code?(so assembly code interacts with hardware)

TIA.
Posted
Updated 23-Aug-14 23:11pm
v2

You are already going in wrong direction: the libraries are not in header files. It would be good if you first learned C++ and linking, and then repeated these questions, in a more correct ways.

Let's say, I could answer: iostream.h for Linix and Windows are the same. This is true. But this truth would only mislead you, because it would miss the more important statement: iostream libraries for Linix and Windows are very different. This is because header files are only used to facilitate interfacing with the library, and the library comes when it is implemented.

To start getting into this, I would advise you to do some simple things: for a minute, forget about all those standard or OS-specific libraries. At first, consider that they are given. And the do this: create some libraries of your own. No matter what they do, could be nothing really useful. And the, study there deployment and use. Model the situation when you pass your library from you to some customer, 10 with source code; 2) without source code. Study the use of object, library and header files, what is more important and what is not, where those files come to the project and what roles do they play; what is mandatory and what is not.

After you do this study, you will really understand the most of your issues, because a library is a library; it is standard only because it is universal enough and good enough, so has been standardized.

Before you figure out those more important things, it would be the best to postpone answering of your other question.

—SA
 
Share this answer
 
v2
Comments
AmiR1999 24-Aug-14 6:15am    
So can i use std::cout without using iostream.h?
Sergey Alexandrovich Kryukov 24-Aug-14 13:23pm    
iostream.h or underlying library? You can do it without iostream.h only if you provide the declarations available in iostream.h somehow, but why? You can do it without the library, only if you provide the code alternative the one contained in the library with the same interface. You could do it, for example, if you want to use alternative hardware (imaging such case).
I hope I answered.
—SA
AmiR1999 27-Aug-14 17:31pm    
Thank you but my main question is that when we use std::cout,how iostream does this?
AmiR1999 24-Aug-14 6:18am    
Would you please explain all questions i asked?
Sergey Alexandrovich Kryukov 24-Aug-14 13:28pm    
Consider I just tried to save some time and optimize this exercise; and this is not only my time. Let's go in iterations: you learn only the first part, about the roles of header files and libraries (ask other questions on this topics if you want) and reformulate the questions based on these knowledge. You can use "Improve question", below the question. Then I'll gladly answer.
—SA
What holds all together is not the header files, but the linker. And that is the main point you seem to be missing.

The linker not only combines multiple compilation units and forms a proper program, it also provides the linkage between an application and the operating system. Whenever your program invokes an operating system service it does that in form of calling a function. And the linker actually is the one who knows, what to do with that call.

Now, how does the linker know all these API calls of the operating system? The operating system presents itself to the linker as being a big library with thousands of functions. And all that knowledge is provided to the linker in the form of library files. So that is the point where the music plays. For example, the libraries that the Windows operating systems is dressed in are called kernel32.lib, user32.lib, gdi32.lib, and so forth.

Header files, in contrast, are a way of telling the compiler, which library functions exist in a library and what their calling conventions are. As an operating systems presents itself to application programs as a big library, you need of course a (or multiple) header files. These come in deed together with the operating system. But as a header file is only a text file, you could in fact write it yourself, if you know the exact form of the API calls the operating system offers.

All that said, here are some answer to your questions (and by now, I guess, you have already figured them by yourself):

Some header files come with the operating system (together with the corresponding library files), some others come with the compiler (e.g. iostream.h), and again others come with every library you integrate into your project.

There are no special keywords for using an operating system API. They are called just like a usual function. (Isn't that a marvelous trick!)

Many libraries do not make use of the operating system directly, but rely on more basic libraries to do that. For example the streaming system of C++ mostly relies on the C++ Runtime Library, which in turn contains the calls into the operating system. And hence, the C++ Runtime library needs to be different for every operating system.

I hope this, together with the good advice that Sergey gave you in Solution 1, will answer your question.
 
Share this answer
 
Comments
AmiR1999 25-Aug-14 13:25pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900