Using #pragma once in headers
Andrew Pinski
pinskia@gmail.com
Wed May 7 02:13:28 GMT 2025
More information about the Binutils mailing list
Wed May 7 02:13:28 GMT 2025
- Previous message (by thread): Using #pragma once in headers
- Next message (by thread): Using #pragma once in headers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, May 6, 2025 at 7:01 PM Fangrui Song <i@maskray.me> wrote: > > On Tue, May 6, 2025 at 5:59 PM Alan Modra <amodra@gmail.com> wrote: > > > > On Tue, May 06, 2025 at 11:58:54AM +0100, Matthieu Longo wrote: > > > Would it make sense to accept "#pragma once" and deviate one millimeter away > > > from the C99 standard instead of using #ifndef ... #define ... #endif ? > > > > I'm mildly against the proposal. Consistency matters. If you were > > starting a new sub-project of binutils then I wouldn't mind. > > > > -- > > Alan Modra > > #pragma once does not deduplicate when symlinks are involved (as > explained by the Wikipedia page). I do not know whether the point is > relevant to binutils. > > ln -s a.h b.h > #include "a.h" > #include "b.h" > > https://thamara.dev/posts/pragma-once-vs-header-guards/ Actually symlinks work with GCC's implementation. It is clang and MSVC's implementation which does not. Now `#pragma once` should not be used at all. In fact it was at one point deprecated in GCC and then undeprecated years later when a new (current) implementation was done. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11569 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45599) was the bug recording the undeprcation of `#pramga once` and the new implementation mentioned the fix of the symlinks issue. Later on when clang was being designed it didn't handle the symlink issue. But GCC's implementation does treat the 2 different files with the same contents as the same: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52566 (is this a bug depending on the definition of once means). Thanks, Andrew > > > The only other technical issue is related to C++ modules > (https://github.com/llvm/llvm-project/issues/77995 fixed by newer > Clang), which is not relevant to us.
- Previous message (by thread): Using #pragma once in headers
- Next message (by thread): Using #pragma once in headers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list