If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
-
theigor
- Experienced Solver

- Posts: 78
- Joined: Thu Jan 12, 2006 6:51 pm
Post
by theigor » Fri Jun 02, 2006 8:38 pm
What's the difference between using
in the beginning of a header file and a
Code: Select all
#ifndef FILE_H
#define FILE_H
...
#endif

-
protocol
- Moderator

- Posts: 680
- Joined: Wed Jan 18, 2006 6:13 pm
- Location: Dallas, TX
-
Contact:
Post
by protocol » Fri Jun 02, 2006 9:30 pm
Thats not a stupid question to me.
They are both the same but:
I wrote:
#pragma once (and #import)
- is compiler specific
&&
the #define conditional works everywhere
Also:
http://en.wikipedia.org/wiki/Pragma_once
-
eco
- Filthy Rich wx Solver

- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
-
Contact:
Post
by eco » Fri Jun 02, 2006 11:35 pm
The wikipedia article is incorrect. #pragma once also works on GCC 3.4+ (it was un-deprecated) and inclusion guards and #pragma once aren't quite the same thing. The result is the same but #pragma once improves compilation speed (see this
Games from Within article for details). Use both to get the speed of #pragma once but still fallback to inclusion guards for compilers which don't support it.
-
cpp
- I live to help wx-kind

- Posts: 195
- Joined: Wed Sep 28, 2005 9:42 pm
Post
by cpp » Sun Jun 04, 2006 2:37 am
mhh, Isnt #pragma once part of ISO compliant C++??
Hier Kommt die Sonne...
-
lowjoel
- Moderator

- Posts: 1511
- Joined: Sun Jun 19, 2005 11:37 am
- Location: Singapore
-
Contact:
Post
by lowjoel » Sun Jun 04, 2006 2:05 pm
Yes, it's meant for "allowing various instructions to be given to a compiler". It is standard, but there may be some features present in compiler 'a' that isn't in compiler 'b', since it is implementation defined. IIRC only VC has #pragma once.
Most compilers wont stop and give an error if they encounter an unknown pragma, most will just issue a warning.
-
eco
- Filthy Rich wx Solver

- Posts: 203
- Joined: Tue Aug 31, 2004 7:06 pm
- Location: Behind a can of Mountain Dew
-
Contact:
Post
by eco » Sun Jun 04, 2006 9:20 pm
To clarify what lowjoel was saying: "#pragma" is part of the standard. "#pragma once" is not. "#pragma" is for issuing compiler specific directives not covered by the standard. VC, for instance, supports warning disabling like this: "#pragma warning ( disable : 4101)". Also, as I said before, VC isn't the only compiler that supports "#pragma once". I know both GCC 3.4+ and Metrowerks support it. Others probably do as well.
-
cpp
- I live to help wx-kind

- Posts: 195
- Joined: Wed Sep 28, 2005 9:42 pm
Post
by cpp » Mon Jun 05, 2006 7:21 am
is it safe to say that #pragrma once (not just pragma), is supported by all modern & good compilers?
Hier Kommt die Sonne...
-
lowjoel
- Moderator

- Posts: 1511
- Joined: Sun Jun 19, 2005 11:37 am
- Location: Singapore
-
Contact:
Post
by lowjoel » Mon Jun 05, 2006 7:35 am
no... IIRC I'd only dare use it under a VC-only environment
-
jbacigal
- Knows some wx things

- Posts: 33
- Joined: Mon Sep 19, 2005 8:22 pm
Post
by jbacigal » Wed Jun 07, 2006 7:36 pm
I generally use the #ifndef #defne header guards and then #pragma once beneath it. I don't think there is any adverse affect to using both - get the compile time boost if #pragma once is supported, if not, you still have inclusion guards.