#pragma once of header guards

Started by
22 comments, last by Khatharr 11 years, 2 months ago

I think he should make an educated decision based on his compiler's performance and how it handles the non-standard behavior.

The difference in performance is going to be completely negligible until he has an absolutely massive project - and even then the compile times will probably be dominated by 3rd party headers, not his own.

As for standard vs non-standard behaviour, it takes less time to discover that than it did for any of us to type out an answer here. If only one of the 2 options is available, the question becomes irrelevant, and if both options are available, the answer is uninteresting - just pick one.

Advertisement

The difference in performance is going to be completely negligible until he has an absolutely massive project

Or unless he has a compiler which is faster through either method. Not all compilers perform this optimization.


An example for the useless benefit that I mentioned earlier, about testing if a file has been included:

http://www.bobarcher.org/software/include/index.html

In the second example, he describes another pattern of including files, where inside of a header file that includes other header files, he first checks if the header had already been included, to save on time and effort to open the file and preprocess it. This may be defeated by #pragma once, but a compiler is allowed to implement #pragma once to be a naive header guard, too.

As for standard vs non-standard behaviour, it takes less time to discover that than it did for any of us to type out an answer here. If only one of the 2 options is available, the question becomes irrelevant, and if both options are available, the answer is uninteresting - just pick one.


He did ask more than which to use; he asked when to use either, and why would one use header guards over #pragma once. I'm just providing arguments for why people would use header guards.

Compiler optimisation or not, the difference there is something like 10ms per file per compile. I can guarantee that you'll waste more time trying to optimise this than you will save.

I'm not criticising you showing why people choose what they do; I'm just saying this is almost completely irrelevant in the grand scheme of making games and that the original poster should pick whatever is simplest for them.

If only one of the 2 options is available, the question becomes irrelevant, and if both options are available, the answer is uninteresting - just pick one.

mrspock1.jpg

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement