mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
PrmPkg: 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>
This commit is contained in:
parent
73be8b8b49
commit
963162cab0
16 changed files with 16 additions and 62 deletions
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_INFO_H_
|
||||
#define PRM_INFO_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <Prm.h>
|
||||
|
|
@ -45,5 +44,3 @@ typedef struct {
|
|||
#define ONE_MICROSECOND (1000)
|
||||
#define ONE_MILLISECOND (1000 * ONE_MICROSECOND)
|
||||
#define ONE_SECOND (1000 * ONE_MILLISECOND)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_CONTEXT_BUFFER_LIB_H_
|
||||
#define PRM_CONTEXT_BUFFER_LIB_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <PrmContextBuffer.h>
|
||||
|
|
@ -95,5 +94,3 @@ GetContextBuffer (
|
|||
IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTIONAL,
|
||||
OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_MODULE_DISCOVERY_LIB_H_
|
||||
#define PRM_MODULE_DISCOVERY_LIB_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <PrmContextBuffer.h>
|
||||
|
|
@ -56,5 +55,3 @@ DiscoverPrmModules (
|
|||
OUT UINTN *ModuleCount OPTIONAL,
|
||||
OUT UINTN *HandlerCount OPTIONAL
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_PECOFF_LIB_H_
|
||||
#define PRM_PECOFF_LIB_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <PrmExportDescriptor.h>
|
||||
|
|
@ -107,5 +106,3 @@ GetExportEntryAddress (
|
|||
IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory,
|
||||
OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_H_
|
||||
#define PRM_H_
|
||||
#pragma once
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <PrmContextBuffer.h>
|
||||
|
|
@ -48,5 +47,3 @@ EFI_STATUS
|
|||
IN VOID *ParameterBuffer OPTIONAL,
|
||||
IN PRM_CONTEXT_BUFFER *ContextBuffer OPTIONAL
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_CONTEXT_BUFFER_H_
|
||||
#define PRM_CONTEXT_BUFFER_H_
|
||||
#pragma once
|
||||
|
||||
#include <PrmDataBuffer.h>
|
||||
#include <PrmMmio.h>
|
||||
|
|
@ -167,5 +166,3 @@ typedef struct {
|
|||
} PRM_MODULE_CONTEXT_BUFFERS;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_DATA_BUFFER_H_
|
||||
#define PRM_DATA_BUFFER_H_
|
||||
#pragma once
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
|
|
@ -47,5 +46,3 @@ typedef struct {
|
|||
} PRM_DATA_BUFFER;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_EXPORT_DESCRIPTOR_H_
|
||||
#define PRM_EXPORT_DESCRIPTOR_H_
|
||||
#pragma once
|
||||
|
||||
#include <Prm.h>
|
||||
|
||||
|
|
@ -106,4 +105,3 @@ typedef struct {
|
|||
{ __VA_ARGS__ } \
|
||||
} \
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_MMIO_H_
|
||||
#define PRM_MMIO_H_
|
||||
#pragma once
|
||||
|
||||
#include <Uefi.h>
|
||||
|
||||
|
|
@ -41,5 +40,3 @@ typedef struct {
|
|||
} PRM_RUNTIME_MMIO_RANGES;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_MODULE_H_
|
||||
#define PRM_MODULE_H_
|
||||
#pragma once
|
||||
|
||||
#include <Prm.h>
|
||||
#include <PrmContextBuffer.h>
|
||||
|
|
@ -44,4 +43,3 @@
|
|||
IN PRM_CONTEXT_BUFFER *ContextBuffer \
|
||||
) \
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_MODULE_IMAGE_CONTEXT_H_
|
||||
#define PRM_MODULE_IMAGE_CONTEXT_H_
|
||||
#pragma once
|
||||
|
||||
#include <IndustryStandard/PeImage.h>
|
||||
#include <Library/PeCoffLib.h>
|
||||
|
|
@ -24,5 +23,3 @@ typedef struct {
|
|||
} PRM_MODULE_IMAGE_CONTEXT;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_CONFIG_H_
|
||||
#define PRM_CONFIG_H_
|
||||
#pragma once
|
||||
|
||||
#include <PrmContextBuffer.h>
|
||||
#include <Uefi.h>
|
||||
|
|
@ -27,5 +26,3 @@ struct _PRM_CONFIG_PROTOCOL {
|
|||
};
|
||||
|
||||
extern EFI_GUID gPrmConfigProtocolGuid;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_MODULE_DISCOVERY_H_
|
||||
#define PRM_MODULE_DISCOVERY_H_
|
||||
#pragma once
|
||||
|
||||
#include <PrmModuleImageContext.h>
|
||||
|
||||
|
|
@ -35,5 +34,3 @@ PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *
|
|||
CreateNewPrmModuleImageContextListEntry (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRMT_ACPI_TABLE_H_
|
||||
#define PRMT_ACPI_TABLE_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <IndustryStandard/Acpi10.h>
|
||||
|
|
@ -92,5 +91,3 @@ typedef struct {
|
|||
PhysicalAddress, /* UINT64 PhysicalAddress */ \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif // _PRMT_ACPI_TABLE_H_
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef PRM_STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE_H_
|
||||
#define PRM_STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE_H_
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
|
||||
|
|
@ -20,5 +19,3 @@ typedef struct {
|
|||
BOOLEAN Policy2Enabled;
|
||||
UINT8 SomeValueArray[SOME_VALUE_ARRAY_MAX_VALUES];
|
||||
} STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef HPET_REGISTER_H_
|
||||
#define HPET_REGISTER_H_
|
||||
#pragma once
|
||||
|
||||
#define HPET_BASE_ADDRESS 0xFED00000
|
||||
#define HPET_RANGE_LENGTH 0x1000
|
||||
|
|
@ -104,5 +103,3 @@ typedef union {
|
|||
} HPET_TIMER_MSI_ROUTE_REGISTER;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue