My two bits as a user of Qt.  Please make sure any exposed headers use the 
old-school guards and NOT the #pragma once.

I don’t care how the internal Qt headers work.  However, Ive been burned too 
many times by the "known issues" of the #pragma once to want to use them.

The problem isn’t if the two headers are the same, the problem is it not 
compiling because of multiple definitions of classes.

The main issue I have, is we build a tool with tons of sub libraries and 
modules, with a pretty poor build environment.  We have 800+ developers using 
it, so any change is done by a committee and takes years ☹

Our Qt gets places in a area everyone gets access to. Ie 
/usr/local/shared_data/Qt on linux and a mount Q:/Qt/ on windows, but Q: can 
all be accessed via //SHAREPOINT/shared_data/Qt

Under Qt might be Qt5.12.9 and Qt5.15.10, but for this example lets assume its 
not versioned.  Under each version, we then have the compiler sub directories.  
Meaning win64VC15, linux_x86_64/debug and linux_x86_64/release.  The windows 
disty contains debug and release.  

What happens, is the compiler does not see Q:/Qt/win64VC15/include as the same 
path as //SHAREPOINT/shared_data/Qt/ win64VC15/include.  This is a known issue.

I 100% understand that we should fix out build system so they only access any 
data in the shared_data mount the same way.  However that is simply easier said 
than done relying on #pragma once just fails for us.  

Ive seen this issue at a number of companies that do multi-platform development 
but store their Qt versions on a server.

Scott

-----Original Message-----
From: Development <development-boun...@qt-project.org> On Behalf Of Volker 
Hilsheimer via Development
Sent: Monday, October 10, 2022 2:55 AM
To: development@qt-project.org
Subject: [Development] Using '#pragma once' instead of include guards?

Hi,


We are using `#pragma once` in a number of examples and tests in the Qt source 
tree, but I don’t think we have officially endorsed it in favour of explicit 
include guards.

#pragma once is “non-standard but widely supported” [1], with some caveats, 
e.g. when there are multiple header files with the same name (which each 
compiler then handles differently, as there is no standard).

From what I see, it should in practice be ok to use. But perhaps I’m missing 
something. Does anything speak against using ‘#pragma once’ in new files?


Volker

[1] https://en.wikipedia.org/wiki/Pragma_once

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development
_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to