diff options
| author | Michael Kubacki <michael.kubacki@microsoft.com> | 2026-02-03 21:48:28 +0300 |
|---|---|---|
| committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2026-02-24 00:01:28 +0300 |
| commit | 7a934d0befca7d10f361c76af6d2fcb6eb48c835 (patch) | |
| tree | fd2c79d19ea830e56c72e0a80fbe24a9cd3445d7 /MdeModulePkg/Universal/ReportStatusCodeRouter | |
| parent | 648ea00a192c35eb62108d93e7db909e3afd0ca1 (diff) | |
| download | edk2-7a934d0befca7d10f361c76af6d2fcb6eb48c835.tar.xz | |
MdeModulePkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Diffstat (limited to 'MdeModulePkg/Universal/ReportStatusCodeRouter')
3 files changed, 3 insertions, 12 deletions
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h index ce09aa8a53..6d07186b67 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.h @@ -6,8 +6,7 @@ **/
-#ifndef __PEI_REPORT_STATUS_CODE_ROUTER_H__
-#define __PEI_REPORT_STATUS_CODE_ROUTER_H__
+#pragma once
#include <Ppi/ReportStatusCodeHandler.h>
#include <Ppi/StatusCode.h>
@@ -96,5 +95,3 @@ ReportDispatcher ( IN CONST EFI_GUID *CallerId OPTIONAL,
IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
);
-
-#endif
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.h index 2e08ac8851..2e877db97c 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.h +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.h @@ -6,8 +6,7 @@ **/
-#ifndef __REPORT_STATUS_CODE_ROUTER_RUNTIME_DXE_H__
-#define __REPORT_STATUS_CODE_ROUTER_RUNTIME_DXE_H__
+#pragma once
#include <Protocol/ReportStatusCodeHandler.h>
#include <Protocol/StatusCode.h>
@@ -129,5 +128,3 @@ ReportDispatcher ( IN EFI_GUID *CallerId OPTIONAL,
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
);
-
-#endif
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h index 51b98244e3..9f59cfcfe5 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h @@ -6,8 +6,7 @@ **/
-#ifndef __REPORT_STATUS_CODE_ROUTER_COMMON_H__
-#define __REPORT_STATUS_CODE_ROUTER_COMMON_H__
+#pragma once
#include <Protocol/MmReportStatusCodeHandler.h>
#include <Protocol/MmStatusCode.h>
@@ -111,5 +110,3 @@ EFI_STATUS GenericStatusCodeCommonEntry (
VOID
);
-
-#endif
|
