Jump to content
  • Advertisement


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


What it means: #pragma once

This topic is 5410 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

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 this post

Link to post
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 ...


That's an include guard.

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


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

Share this post

Link to post
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


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

Aeon Games

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!