Can we rely on #pragma once ?

Ismael Luceno ismael at iodev.co.uk
Mon Feb 19 23:49:17 UTC 2024


El 19 de febrero de 2024 11:13:34 UTC, "Enrico Weigelt, metux IT consult" <info at metux.net> escribió:
>Hello folks,
>
>we've got a lot of include files, therefore lots of guards.
>
>Modern C compilers should understand #pragma once, but this isn't
>without problems (possibly problematic with symlinks ?), and I have
>to admit I don't how well is it supported outside of GNU land.
>
>Can we rely on it ?
>

You can expect compilers to optimise for #ifdef guards exactly in the same way, so no gain. At least GCC and Clang do, see:
* <https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html>
* <https://clang.llvm.org/docs/InternalsManual.html#the-multipleincludeopt-class>




More information about the xorg-devel mailing list