Jump to content
  • Advertisement
Sign in to follow this  
Noods

#pragma once vs. include guards

This topic is 3729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have read up on the pros and cons of #pragma once and include guards but I wanted to get a few opinions. Do you find yourself using #pragma once or include guards?

Share this post


Link to post
Share on other sites
Advertisement
I use include guards, simply because Code::Blocks puts them there for me :)

I'm unsure there will be any difference between the two, I think most compilers have now caught up and handle it accordingly. Maybe some console developers here have some opinions?

Share this post


Link to post
Share on other sites
Include guards. I really doubt that the time saved by using #pragma once will be noticible. If in doubt, you can always use both to get the best of both worlds.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
Pragma once will never hurt.

Unless your code is compiled by an older version of gcc or LCC, both of which have had buggy implementation of pragma once such symbolic or hard links would confuse them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Crypter
#pragma once is not guaranteed to be supported on all compiliers. Thus I personally use inclusion guards.

Yup that was my understanding and so I see inclusion guards being used in any books that are trying to be portable like Stroustroup's.
I just finished reading Horton's book on Visual Studio and he uses #pragma once all through the book and even admits it may not work on all compilers but still uses it since that's what Visual Studio uses. Personally, I use #pragma once if I can get away with it since I'm a lazy programmer and it's less typing;)

p.s. Actually, if you are using any of the various Microsoft wizards to generate MFC programs or something else it will automatically stick #pragma once in your header files for you!


[Edited by - daviangel on September 28, 2008 5:14:19 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by Promit
Pragma once will never hurt.

Unless your code is compiled by an older version of gcc or LCC, both of which have had buggy implementation of pragma once such symbolic or hard links would confuse them.
Although it seems odd to have symlinks or hardlinks involved, I suppose that's a fair enough reason otherwise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!