[Development] Using #pragma once

Gunnar Roth gunnar.roth at gmx.de
Sun Oct 7 14:30:52 CEST 2018


Hi Lars,
I do not really object exclusive use of pragma once, without header 
guards  ( I use it myself), I just want to tell about my experience on 
Debian Stretch with gcc 6.3

1. Using precompiled header, you can run into trouble, if you use 
forward header , like qt does, and these do not contain pragma once too. 
I got double definition errors then, because pragam once was ignored 
somehow.

2. There is a , still unfixed, gcc bug since gcc 4.6.3 , where pragma 
once is ignored for files which start with a Utf8 BOM, when using 
precompiled headers.  see 
https://gcc.gnu.org/bugzilla/show_bug.cgi?format=multiple&id=56549

3. #pragma once makes gcc much  slower according to Bug 58770 - GCC very 
slow compiling with #pragma once 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770


Regards,
Gunnar Roth



------ Original Message ------
From: "Lars Knoll" <lars.knoll at qt.io>
To: "Qt development mailing list" <development at qt-project.org>
Sent: 07/10/2018 10:56:47
Subject: [Development] Using #pragma once

>Hi,
>
>Just a quick question: Does anybody have any good arguments against us 
>starting to use #pragma once instead of header guards throughout our 
>code base?
>
>I’ve started using it implicitly when updating 3rd party code (the 
>macro assembler) in qtdeclarative without any problems (so I’d 
>supported by all our compilers). IMO #pragma once is both safer and 
>nicer to use than classic header guards.
>
>Cheers,
>Lars
>
>_______________________________________________
>Development mailing list
>Development at qt-project.org
>http://lists.qt-project.org/mailman/listinfo/development




More information about the Development mailing list