Archived

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

What it means: #pragma once

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

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