Possible Duplicate:
#pragma - help understanding
I saw the pragma
many times,but always confused, anyone knows what it does?Is it windows only?
In the C and C++ programming languages, #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Thus, #pragma once serves the same purpose as #include guards, but with several advantages, including: less code, avoiding name clashes, and improved compile speed.
See the Wikipedia article for further details.
It's used to replace the following preprocessor code:
#ifndef _MYHEADER_H_ #define _MYHEADER_H_ ... #endif
A good convention is adding both to support legacy compilers (which is rare tho):
#pragma once #ifndef _MYHEADER_H_ #define _MYHEADER_H_ ... #endif
So if #pragma once fails the old method will still work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With