Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should C++ eliminate header files? [closed]

People also ask

What happens if we remove header file from C program?

If you don't the compiler will use the default prototype for undeclared functions, which is: int functionName(int argument); So it will compile, and link if the functions are available. But you will have problems at runtime.

Are header files necessary in C?

In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

Can we run C program without header files?

Yes you can wirte a program without #include , but it will increase the complexity of the programmer means user have to write down all the functions manually he want to use.It takes a lot of time and careful attention while write long programs.

Why is header file important in C?

The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program. In C, the usual convention is to give header files names that end with .


Backwards Compatibility - Header files are not eliminated because it would break Backwards Compatibility.


Header files allow for independent compilation. You don't need to access or even have the implementation files to compile a file. This can make for easier distributed builds.

This also allows SDKs to be done a little easier. You can provide just the headers and some libraries. There are, of course, ways around this which other languages use.


Even Bjarne Stroustrup has called header files a kludge.

But without a standard binary format which includes the necessary metadata (like Java class files, or .Net PE files) I don't see any way to implement the feature. A stripped ELF or a.out binary doesn't have much of the information you would need to extract. And I don't think that the information is ever stored in Windows XCOFF files.


I routinely flip between C# and C++, and the lack of header files in C# is one of my biggest pet peeves. I can look at a header file and learn all I need to know about a class - what it's member functions are called, their calling syntax, etc - without having to wade through pages of the code that implements the class.

And yes, I know about partial classes and #regions, but it's not the same. Partial classes actually make the problem worse, because a class definition is spread across several files. As far as #regions go, they never seem to be expanded in the manner I'd like for what I'm doing at the moment, so I have to spend time expanding those little plus's until I get the view right.

Perhaps if Visual Studio's intellisense worked better for C++, I wouldn't have a compelling reason to have to refer to .h files so often, but even in VS2008, C++'s intellisense can't touch C#'s