[Qt-creator] Use #pragma once as default instead of header guards
chighland at gmail.com
Wed Jan 13 16:43:05 CET 2016
On Wed, Jan 13, 2016 at 4:52 AM, Joerg Bornemann
<joerg.bornemann at theqtcompany.com> wrote:
> On 13-Jan-16 13:38, Ziller Eike wrote:
>> Let’s drop the argument about the clang code model from the discussion
>> about whether to use #pragma once or not.
> Still, as it came up, this argument raises the interesting question what
> will happen to users of the clang code model that cannot switch to
> (non-standard) pragma once for this or that reason?
#pragma once isn't non-standard. It's defined by the C++11
specification and a compliant compiler MUST support it.
The real problem with #pragma once is that most implementations rely
on filesystem identity to support it, which means that if you somehow
get to two different copies of the header file (perhaps you include it
yourself with "" and then something you include includes it with <>,
and the pathing finds separate copies) the pragma won't stop the
collision while classic header guards will.
This isn't a reason not to support the pragma, of course. But that
combined with its lack of standardization in C++03 is a reason not to
default to it in a template.
More information about the Qt-creator