-4

Like #include <bits/stdc++.h> which replaces all header files in C++

is their a similar header file in C which can replace all header files ?

[ does a header file even exists in C ? ]

it should replace all header files like

#include<stdio.h>

#include<conio.h>

#include<math.h>

...and so on.

if the answer is NO can you tell why? (concisely)

  • You can copy and paste all header files into one header file. – mkrieger1 May 28 '21 at 09:31
  • you can go to your include folder and add your own header file with all your desired header file. then you can include that file anywhere you want – sadbro May 28 '21 at 09:31
  • 1
    "that is used to replace all header files in C++" it is a common misunderstanding that `#include ` would be a C++ thing. It is not. [Why should I not `#include `?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – 463035818_is_not_an_ai May 28 '21 at 09:32
  • @mkrieger did u mean to say to create a user defined header file and add header files all in that ? –  May 28 '21 at 09:32
  • @sadbro yeah its a good idea , but isn't their a pre-defined one like #include . in C ? –  May 28 '21 at 09:34
  • Why should one want to do this? Why do you? Based on which properties should a header be included in the collection? See, there are multiple standard headers, but the number is not too high. If a source file includes "too many" headers, it most probably is too big itself and should be divided. – the busybee May 28 '21 at 09:37
  • @ the busy bee yeah its a fact that `#include` adds a lot of junk to a program but it only effects if you are really concerned about its effects like if you are doing a Competitive Programing question then listing all header files would take time so for people not much effected by use of `#include` like Competitive programmers its a good thing to know a header file which can replace all header files –  May 28 '21 at 09:42
  • 1
    frankly, if you understood `#include` and why it is considered "bad practice" it should be trivial to write your own header that does the same. But again, why would you? – 463035818_is_not_an_ai May 28 '21 at 09:54
  • 2
    Don't do that. Properly written C code only includes the resources that it uses. Good design keeps resources as local as possible. The reasons why are many: private encapsulation, loose coupling, less namespace clutter, self-documenting code, faster compile/build. – Lundin May 28 '21 at 10:27
  • as a pre-build step: `find / -name "*.h" | awk '$0=#include "$0";' > everything.h` followed by `#include "everything.h"` and hope that there are always appropriate header guards? – Caleth May 28 '21 at 10:34
  • @Caleth I dint get you....... should i add `find / -name "*.h" | awk '$0=#include "$0";' > everything.h` .... and .... `#include "everything.h"` before the start of program ?? instead of header files to call all header files did u mean this ? –  May 28 '21 at 11:29
  • The first part is a bash script that writes a header which includes every .h file on your filesystem – Caleth May 28 '21 at 11:34
  • @Caleth yeah ...the bash script what you have written where should i put that ?, before `#include "everything.h"` in a program ? and do i need to add any directory path anywhere in the bash script or just can i copy paste what you have written in bash script ? –  May 28 '21 at 11:38
  • It was a joke. You run the command before compiling your program, e.g. if you use `make` to compile, you'd add it as a rule in your Makefile, and then every header anywhere on your filesystem is included – Caleth May 28 '21 at 11:41
  • @Caleth ohh okay i taught we could add all header files in a user defined header file with these Terminal Commands !!!! .... instead of listing all of them ...... –  May 28 '21 at 11:46
  • Not sure why this question got downvoted. It's a reasonable question. (Might be a dup, at worst.) – Steve Summit Jun 12 '21 at 15:10

3 Answers3

4

No.

The minimum answer needs to be 30 characters, but there is nothing much to add.

Cheatah
  • 1,825
  • 2
  • 13
  • 21
1

I guess you're asking about a hypothetical

#include <libc.h>

that would get you everything you needed, for everything in the standard C library, in one fell swoop.

My answers are "No, there is nothing like this", and "Because the apparent convenience this would give you is misplaced, or not as important as it seems".

Certainly, I understand the desire. It used to really bug me that in practically every C source file I wrote, I had to include <stdio.h> and <string.h> and <stdlib.h> and all the rest.

In fact, early in my C programming career, I created my own libc.h that included everything else. But I think I only used my libc.h for a couple of months, in a couple of programs, and then I stopped using it and forgot all about it.

When you're just learning C, trying to remember which header files to include is one of those issues that looms large. Once you're used to it, though, it's really not a big deal. When you're no longer learning C, but rather, writing larger and more realistic programs, you spend the majority of your time designing and writing and debugging and maintaining the actual logic of your program. You spend relatively little time figuring out which header files to include. So an "improvement" to make it easier to include the right header files would not end up buying you much.

The other thing to realize is that including everything every time (meaning that you always get a bunch of stuff you don't need) is likely to have some costs. It could have a significant impact on compilation time. It could increase the likelihood of conflicts between your own symbols, and symbols defined in a header file. There are ways to mitigate those problems, but the mitigations have costs, too.

This is not the concise answer you were looking for, I suspect. And I have to agree: today, now that the C library is well standardized, it would be possible to have one single header file, and it would save everyone a certain amount of time. But things have been the way they are for so long, and the advantages of devising a new, "universal" header file are small enough, and the amount of contentious debate that would be engendered by proposing one is large enough, that I doubt it would ever happen.

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
0

NO

their is no header file in C similar to

#include<bits/stdc++.h> 

This is only present in C++

But if you are feed up of listing all header files

Just create a header file of your means create a user defined header file and store all other header files under it then all your header files can be replaced by one universal header file that you created

the simple reason for why no such header file exists is, these type of header files create a junk in the program hence it's not included in the standard library of C

and its advised not to use #include<bits/stdc++.h> in C++