#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]
#pragma once
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?
AFAIK it is not consistent across compilers. .net uses just #pragma once but I would not like to trust to portability on that one.
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.
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...
#pragma once works in GCC too I just wish that they could release the version that does...
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).
quote:Original post by Jan WassenbergDo 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.
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).
If I recall correctly,
- CD
// Brought to you by Code_Dark | [( Politics Forum Beta-Test )]
[edited by - Code_Dark on April 13, 2004 7:46:56 PM]
#pragma once
is a deprecated piece of code that shouldn't be used. Sucks, I know... it was a useful little friend. However, it's definitely better to stay standard and not use it - CD
// Brought to you by Code_Dark | [( Politics Forum Beta-Test )]
[edited by - Code_Dark on April 13, 2004 7:46:56 PM]
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement