Jump to content
  • Advertisement

Archived

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

hardest1v7

What it means: #pragma once

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

Advertisement
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 ...

#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 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:

#ifndef NAMEOFHEADERFILE_H
#define NAMEOFHEADERFILE_H

// Place header file content here

#endif

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!