Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#pragma once of header guards


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#21 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 09 February 2013 - 11:16 AM

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.



Sponsor:

#22 Ectara   Crossbones+   -  Reputation: 3019

Like
0Likes
Like

Posted 09 February 2013 - 12:55 PM

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.

#23 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 09 February 2013 - 06:53 PM

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.



#24 Khatharr   Crossbones+   -  Reputation: 3031

Like
1Likes
Like

Posted 09 February 2013 - 09:14 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS