Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Barguast

#pragma once

This topic is 5179 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 was under the impression that this was specific to Visual C++. But according to MSDN it isn't. Is this basically the same thing as doing the following?
#ifndef FOO
#define FOO

...

#endif
 
If so, then why does Visual C++ use both methods? [edited by - Barguast on April 13, 2004 6:21:20 PM]

Share this post


Link to post
Share on other sites
Advertisement
AFAIK it is not consistent across compilers. .net uses just #pragma once but I would not like to trust to portability on that one.

Share this post


Link to post
Share on other sites
quote:
Original post by Trip99
AFAIK it is not consistent across compilers.


Correct. #pragma once will not work on all compilers.

With #ifndef, #define, and #endif, there might be a very small chance for name collision, where as with #pragma once, there ins''t.

Visual C++ uses both methods because it''s just one of those things that''s in there, along with all the other weird stuff.

Share this post


Link to post
Share on other sites
I beleive #pragma once will prevent the file from being opened a second time, the regular header guards won''t work without opening the file and possibly including some 40M lines of headers above the guards.

#pragma once works in GCC too I just wish that they could release the version that does...

Share this post


Link to post
Share on other sites
I read somewhere that VC''s implementation of #pragma once is broken - it can be fooled by including via relative paths. It''s typically only used as an optimization - regular include guards are necessary to guarantee single inclusion. Other compilers are able to detect include guards and keep the information in a table (what #pragma once does in VC, apparently).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Jan Wassenberg
I read somewhere that VC''s implementation of #pragma once is broken - it can be fooled by including via relative paths. It''s typically only used as an optimization - regular include guards are necessary to guarantee single inclusion. Other compilers are able to detect include guards and keep the information in a table (what #pragma once does in VC, apparently).
Do you have any source of information? I''d be interested in details, since I''ve been using VC''s #pragma once for years in both small and large projects and never seen any problems with it.

Share this post


Link to post
Share on other sites
I have only my memory, and a post I just found describing the problem.

This probably won''t happen in most projects, but I sometimes find myself including via (different) relative paths, so it''d blow up with #pragma once only.

Share this post


Link to post
Share on other sites
quote:
Original post by Leffe
#pragma once works in GCC too I just wish that they could release the version that does...


It''s "deprecated" in current versions, and you''ll get warnings if you use it, but they''re bringing it back in GCC 3.4.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!