[Development] #pragma once

Henry Skoglund fromqt at tungware.se
Wed Jan 24 17:30:49 CET 2018


On 2018-01-24 16:19, Ville Voutilainen wrote:
> On 24 January 2018 at 16:30, Oswald Buddenhagen
> <oswald.buddenhagen at qt.io> wrote:
>> but that's only tangentially related to the issue at hand, because the
>> compiler would still pick only one of the files under normal
>> circumstances. a problem would arise if different include styles in
>> different files lead to different headers being picked up from the same
>> -I list. it's fairly hard to construct such a case, and it *probably*
>> doesn't appear inside qt's "regular" build system (that specifically
>> excludes webkit & webengine).
>
>
> That risk is not worth taking. Get your include guards right, and
> don't mess with #pragma once.
> There are tools that can help, but I haven't used them myself, and I
> don't know whether clang
> has anything for this.
>

Thank you for this clarification. I always thought #pragma once is 
superior to include guards, but I didn't really realize that the 
compiler is dealing with two different kind of namespaces (filenames vs 
#defined names), which could cause those problems mentioned above.

For exaample on Windows, if your're including files from a 
server/SMB-share, then I've seen sometimes the including files keep 
their drive letter, e.g P:\\dir\\file.h but sometimes it gets resolved 
into \\computername\\sharename\\dir\\file.h, and it's unclear if a 
#pragma once would treat those as the same file.

Rgrds Henry





More information about the Development mailing list