[Development] Using '#pragma once' instead of include guards?

Hasselmann Mathias mathias at taschenorakel.de
Wed Oct 12 13:23:57 CEST 2022


Am 11.10.2022 um 21:20 schrieb Kevin Kofler via Development:
> "locking you down to a vendor" is a funny argument when the Wikipedia
> article:
> https://en.wikipedia.org/wiki/Pragma_once
> cannot name a single compiler that does not support #pragma once, and 20
> that do.

Yes, it is supported in a way, that each compiler recognizes this 
#pragma and does something compiler specific with it, but what exactly a 
compiler does with it, how each compiler determinates identity is 
purposefully not listed in that table. Well, and that's exactly the 
problem: Nobody really can tell, what any compiler does with the pragma 
and if behavior might change with the next micro patch version.

I am pretty sure, absolutely nobody on this list would object the use of 
#pragma once, if compiler vendors would have documented somewhere, what 
exactly #pragma once means, what identity means, how it is recognized, 
how it is to be implemented. If #pragma once would be a well documented 
and properly implemented industry standard really nobody could object 
its use, as Qt and its users could rely on the spec and ask tooling and 
compiler vendors to fix their software if it doesn't match this 
specification. Still: It isn't. We basically are discussion the use of a 
feature that's entirely undefined and totally in the void. Doing so is 
something for religion, not for engineering.

Ciao
Mathias



More information about the Development mailing list