[Qt-creator] Use #pragma once as default instead of header guards

Mathias Hasselmann mathias at taschenorakel.de
Sun Jan 17 11:12:25 CET 2016


At least GCC implements multi-include optimizations that efficiently 
handle header guards in the pre-processor already. I'd be surprised if 
clang and other compilers are missing that feature.

https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html

So I see some chance that the code model simply doesn't making perfect 
use of clang yet.

In the end it has to efficiently handle header guards anyway as we are 
not going to fix all the system and 3rd party headers our applications 
are using.

So unless there is a significant technical reason why the code model 
cannot be fixed to handle header guards efficiently, this thread is a 
typical bike shed discussion.

Ciao,
Mathias

Am 13.01.2016 um 11:55 schrieb Bubke Marco:
> Hello
>
> With the clang code model there is a problem to generate a preamble file with header guards. Imaging a preamble file is like a automatically pre compiled header for the include block at the top. But there are limitations. One is that every ifndef has to match is #endif inside of the preamble but this not the case for header guards.
>
> #ifndef HEADER_GUARD
> #define HEADER_GUARD
> #include <QtGui> // this would be compiled in the preamble once
>
> void foo()
> {
>     auto bahn = nullptr;
> }
>
>
> #endif
>
> We don't generate a preamble for this case because the opening ifndefs is not matching the endif. In that case the clang model will be very slow!
>
> So I propose we change our wizards to utilize #pragma once and use it for every new file. We can change header files where we need code completion on demand too.
>
> https://en.wikipedia.org/wiki/Pragma_once
>
> Best regards, Marco
>
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator
>



More information about the Qt-creator mailing list