Public Group

#### Archived

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

# What it means: #pragma once

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

## Recommended Posts

please tell me what is "#pragma once". Thanks.

##### Share on other sites
It tells the preprocessor to process the file only once. It''s different than inclusion guards, because those open the file each time it is encountered in the preprocessing process. Like all pragrmas, it is compiler-specific (#pragma once, while supported, is deprecated on GCC).

##### Share on other sites
Edit: Well, not only did Oluseyi beat me to it, he got it right and I didn't. Disregard the stuff below...

It's a preprocessor directive only available on certain compilers (incarnations of VC++ accept it I think, but outside of that I don't know).

It's used to guard against the multiple inclusion problem. When an include file gets included twice within the same file, it causes multiple declaration errors in the compiler. Putting this somewhere in your code only allows any given include file to be included once in a given compilation unit (I think).

It's supposedly equivalent in effect to using include guards in your header files:

#ifndef __MYHEADER_H_#define __MYHEADER_H_... Your header here ...#endif

That's an include guard.

Hope that helps. And if I've got this all wrong, please someone correct me.

-Auron

[edited by - Auron on February 20, 2004 11:52:38 PM]

##### Share on other sites
it tells the MS'' (and I think Borland''s) compiler to include the file only once if the source file that #includes it has already included a header that also include the same header, avoding redefinitions, it can be replaced by:

// Place header file content here

#endif

That''s the prefered way since its not compiler specific.

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999977
×

## Important Information

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

Sign me up!