kzinti wrote:Solar wrote:once in the context of a header file being copied into several locations of the source tree).
Your problem here is that you copied the same header file in several locations, not that you used #pragma once. You could also run into issues with #ifdef/#define if you modified one of these file and forgot to update the other locations. Did you end up copying the file because of the softlink issue above?
The issue was that the
developer thought that "same file name, same contents" would make the compiler consider it the same file and thus avoid redeclaration / redefinition issues. Whereas the compiler considered those separate files.
You're losing a level of control with #pragma once.
kzinti wrote:Solar wrote:I don't really get why anyone would go for a #pragma of any kind for something that can be done perfectly well without.
- Can reduce build time as the compiler doesn't need to open and read the same file again after the first #include of the file in the translation unit.
GCC does not re-read header files since
at least version 3.0...
kzinti wrote:
- Less error prone
To the contrary, which was the reason for my comment. I
despise "automagic" solutions to non-existing problems, because when
those go awry, finding out what your actual problem is can be orders of magnitude more annoying than e.g. a mistyped header guard.
(Have you ever had a hash collision in a Git repository? I have. No fun.)
kzinti wrote:In my experience, I've run into problems with header guards a few times...
All of which boil down to
developer error, not
compiler quirk...
kzinti wrote:...where I've only hit one issue with #pragma once: a compiler that didn't support it in a cross-platform project.
Well, cross-platform is pretty much all I am doing, and in some cases with some
really old compiler. (Dice C on the Amiga.)
Gee, look at the "Caveat" section! Pretty much exactly what I wrote above!