Non-Confidential |
![]() |
ARM DUI0472J | ||
|
||||
Home > Compiler-specific Features > #pragma once |
This pragma enables the compiler to skip subsequent includes of that header file.
#pragma once
is accepted for compatibility with other compilers, and
enables you to use other forms of header guard coding. However, it is preferable to use
#ifndef
and #define
coding because this is more
portable.
The following example shows the placement of a #ifndef
guard around the
body of the file, with a #define
of the guard variable after the
#ifndef
.
#ifndef FILE_H
#define FILE_H
#pragma once // optional
... body of the header file ...
#endif
The #pragma once
is marked as optional in this example. This is because
the compiler recognizes the #ifndef
header guard coding and skips
subsequent includes even if #pragma once
is absent.