khaveesh / macOS-stdc.h

Support for <bits/stdc++.h> in macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

macOS <bits/stdc++.h>

Support for <bits/stdc++.h> in macOS

macOS ships by default with the LLVM/Clang compiler which does not support GNU/GCC extensions such as the bits/stdc++.h header file that every beginner tends to use in their C++ code.

This is a problem even when you use g++ in macOS, as Apple use g++ as a front-end to clang++ for legacy reasons.

Solution

  1. You need to create a directory ‘bits’ under the folder /usr/local/include. This can be done by running the following command in the Terminal:

    mkdir /usr/local/include/bits
  2. You need to copy the contents of the stdc++.h file included in this repository into the newly created bits folder:

    curl https://raw.githubusercontent.com/khaveesh/macOS-stdc.h/master/stdc%2B%2B.h > /usr/local/include/bits/stdc++.h
  3. Profit! You can now write:

    #include <bits/stdc++.h>

Recommendation

There is a reason why Apple (Clang) and even Microsoft (Visual C++) do not include this header file in their compilers. It’s really bad coding practice to include this file.

Explanation

bits/stdc++.h is a non-standard header file containing a list of all header files available in the GCC stdc++ library. Everyone who has written at least a moderately complex program in C++, knows how much of a pain-in-the-a** it is, to find the appropriate header file for all the builtins used. So it is an easier way out to just include bits/stdc++.h. But this means that all header files regardless of whether you’re using them or not, are included in your code. This increases the compilation time of your code. This is especially detrimental in Competitive Programming where coders usually change one or two lines at max and frequently recompile when debugging. Thus this delay in compilation adds up. So it is better to spend some time to analyse which functions you’re using and include only the minimal number of required header files.

TL;DR

Copy and paste the following commands in your Mac terminal:

  1. mkdir /usr/local/include/bits

  2. curl https://raw.githubusercontent.com/khaveesh/macOS-stdc.h/master/stdc%2B%2B.h > /usr/local/include/bits/stdc++.h

But this is bad coding practice and you should consider this only as a stopgap solution and refrain from using it.

Source

The stdc++.h file is derived from the latest stdc++.h file in the GCC git repository with the non-Mac include directives removed.

License: GPLv3

Fun Fact: This license was one of the primary reasons why Apple decided to fund the fledgling LLVM Compiler team in the University of Illinois. Read Apple’s Great GPL Purge to know more.

About

Support for <bits/stdc++.h> in macOS

License:GNU General Public License v3.0


Languages

Language:C++ 100.0%