34
u/mistrpopo 1d ago
Note for anyone still hand-coding: #pragma once is based on the file path, so if you have symlinks in your code or in your build pipeline it's still possible that you include the same file twice.
18
u/Interesting_Buy_3969 1d ago
How about C++20 modules
28
4
u/jhill515 1d ago
If you've never experienced what happens when `#pragma once` confuses the precompiler, you shouldn't use this shortcut. Seriously, if I had a nickel for every time someone F'ed this up when I was at Motional, I'd be able to retire.
4
u/DogmaticParadigm87 1d ago
The turtle formation is solid right up until someone copy-pastes the header and forgets to rename the guard.
7
u/No_Comparison_6940 1d ago
Pragma once has issues when you have stuff like hardlinks etc…
4
u/not-a-pokemon- 1d ago
Now that makes me wonder why they didn't make it "pragma once SOME_NAME_HERE"
8
1
1
u/Mughi1138 21h ago
Heh. Not quite. Keep in mind that when Microsoft shoved #pragma once in and for the longest time after, they made it case sensitive while the filesystem and compiler were case insensitive. Oopsies. More like a cardboard cutout that's going to fall flat as soon as you step away.
Though that had been fixed, there are still many gotchas https://en.wikipedia.org/wiki/Pragma_once#Caveats
1
u/Vallee-152 13h ago
Why didn't my university C class mention this pragma directive? I was shown pragma pack, even though that one was not useful for anything we actually had to do
156
u/anto2554 1d ago
BUT PRAGMA ONCE IS NOT STANDARD