#pragma compiler specific extensionThe pragma directive is used to access compiler-specific preprocessor extensions. A common use of #pragma is the #pragma once directive, which asks the compiler to include a header file only a single time, no matter how many times it has been imported:
#pragma once // header file codeIn this example, using #pragma once is equivalent to an include guard that prevents the file from being processed multiple times.
#ifndef _FILE_NAME_H_ #define _FILE_NAME_H_ /* code */ #endif // #ifndef _FILE_NAME_H_
The #pragma directive can also be used for other compiler-specific purposes. #pragma is commonly used to suppress warnings. For example, in MSVC
#pragma warning (disable : 4018 )
Can be used to disable warning 4018, warning of signed/unsigned mismatch. While you should be reluctant to suppress warnings sometimes it is necessary.
For more uses of the #pragma directive, consult your compiler's documentation.
C preprocessor tutorial