Any recommended practices for cleaning up ‘header spaghetti’ which is causing extremely slow compilation times (Linux/Unix)?
Is there any equvalent to ‘#pragma once’ with GCC?
(found conflicting messages regarding this)
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you’re familiar with ‘include guards’ (#ifdef at the begining of the header..), an additional way of speeding up build time is by using external include guards. It was discussed in ‘Large Scale C++ Software Design‘. The idea is that classic include guards, unlike #pragma once, do not spare you the preprocessor parsing required to ignore the header from the 2nd time on (i.e. it still has to parse and look for the start and end of the include guard. With external include guards you place the #ifdef’s around the #include line itself.
So it looks like this:
and of course within the H file you have the classic include guard
This way the myheader.h file isn’t even opened / parsed by the preprocessor, and it can save you a lot of time in large projects, especially when header files sit on shared remote locations, as they sometimes do.
again, it’s all in that book. hth