C++

not all compilers support `#pragma once` (I think?)

Both, not all compilers support `#pragma once` (I think?), and if they do you don't lose anything by having guards as well.
You already invited:

JOSHUA

Upvotes from: meilinda agrath

Whatever you do: Choose one. The main advantage of pragma once is its simplicity and you loose that when combining both. Instead you get the worst of both worlds: A complicated solution, possibility of name clashes and non-standard code.

leo

Upvotes from: agrath

Usage of preprocessor directives is also blazing fast and optimised out in Clang, due to the internal mapping of the buffer. Once a file has been parsed, the preprocessor state keep _a lot of_ information on where stuff (macrodefs) are... so next time a file is encountered, it already knows the guarding def is guarding from line 3 to line 23478. All you'll get parsed and re-included is the head and tail newlines, at worst case.

AOD

Upvotes from:

I’d say the main advantage of pragma once is that it requires one line in one place (not at the start and at the end). and you lose it this way

Bob

Upvotes from:

Regardless of internal compiler optimizations, `#pragma once` is simpler, more readable, and cleaner. E.g. Nobody has to scroll to the end of the file to see if there is anything extraneous after the last include guard.

ahmad

Upvotes from:

if your compilers support pragma once, its cool - use it! :slightly_smiling_face:
IIRC you can run into problems with `pragma once` when you play with symlinks... but havent tested it to be precise

If you wanna answer this question please Login or Register