| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Tue Sep 25, 2007 8:45 pm Post subject: #pragma once? |
|
|
In C++ I sometimes see code and they are using #pragma once, I mean what does that even do?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Tue Sep 25, 2007 8:55 pm Post subject: |
|
|
| Insures the header file will only be included once (so you don't run into problems like type and function redefinitions)
|
|
| Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Wed Sep 26, 2007 2:52 am Post subject: |
|
|
| How do you use this exactly?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Sep 26, 2007 3:53 am Post subject: |
|
|
Just add #pragma once to the top of the file.
It's a newer method of doing:
| Code: | #ifndef _H_INCLUDE_NAME_
#define _H_INCLUDE_NAME_
// Your Code Here
#endif // _H_INCLUDE_NAME_ |
|
|
| Back to top |
|
 |
TerryDonahugh Master Cheater
Reputation: 0
Joined: 12 Sep 2007 Posts: 412 Location: .nl
|
Posted: Wed Sep 26, 2007 2:47 pm Post subject: |
|
|
| Wiccaan wrote: | Just add #pragma once to the top of the file.
It's a newer method of doing:
| Code: | #ifndef _H_INCLUDE_NAME_
#define _H_INCLUDE_NAME_
// Your Code Here
#endif // _H_INCLUDE_NAME_ |
|
Not really a newer way to do it, it is a Microsoft extension to the language. #pragma once is not standardized and has even been obsoleted in GCC.
Note that #pragma is used for vendor specific extensions to C/C++.
_________________
Last edited by TerryDonahugh on Thu Sep 27, 2007 2:52 am; edited 1 time in total |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Sep 26, 2007 6:16 pm Post subject: |
|
|
I mainly code in VS which is why I mentioned it being 'newer'. As Microsoft notes too, #pragma once can greatly increase compile times, but as you already said, portability comes into play then as some compilers, like GCC, have issues with it which label it obsolete.
According to the Wiki:
LCC (2004) labeled it as having issues.
GCC (1998) labeled it as having issues, then 2005 as obsolete.
For me since I code mainly in VS2005, I just use #pragma once. Most of my old work has been closed source so I never had to worry about others having to compile my stuff so I never bothered with the other method except for older projects when I used VS6.
|
|
| Back to top |
|
 |
|