Giter Club home page Giter Club logo

macos-stdc.h's Introduction

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.

macos-stdc.h's People

Contributors

kevin1010607 avatar khaveesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.