Skip to content

Commit

Permalink
Add header guards missing in some files
Browse files Browse the repository at this point in the history
Some header files, such as those which define structures or classes,
cannot be included more than once within a translation unit, as doing
so would cause a redefinition error. Such headers must be guarded to
prevent ill-effects from multiple inclusion. Similarly, if header
files include other header files, and this inclusion graph contains
a cycle, then at least one file within the cycle must contain header
guards in order to break the cycle. Because of cases like these, all
headers should be guarded as a matter of good practice, even if they
do not strictly need to be.

Furthermore, most modern compilers contain optimizations which are
triggered by header guards. If the header guard strictly conforms
to the pattern that compilers expect, then inclusions of that
header other than the first have absolutely no effect: the file
isn't re-read from disk, nor is it re-tokenised or re-preprocessed.
This can result in a noticeable, albeit minor, improvement to
compilation time.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Dec 12, 2023
1 parent c67a13e commit e20fe27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MsCorePkg/Include/Library/DeviceSpecificBusInfoLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef DEVICE_SPECIFIC_BUS_INFO_LIB_H_
#define DEVICE_SPECIFIC_BUS_INFO_LIB_H_

typedef enum {
Ignore, // Do not check link speed
Gen1, // 2.5 GT/s
Expand Down Expand Up @@ -72,3 +75,5 @@ ProcessPciDeviceResults (
IN UINTN ResultCount,
IN DEVICE_PCI_CHECK_RESULT *Results
);

#endif
5 changes: 5 additions & 0 deletions MsWheaPkg/HwhMenu/CreatorIDParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Copyright (c) Microsoft Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef CREATOR_ID_PARSER_H_
#define CREATOR_ID_PARSER_H_

/**
* Parses the Creator ID which, for now, just prints the GUID
*
Expand All @@ -19,3 +22,5 @@ VOID
ParseCreatorID (
IN CONST EFI_GUID *CreatorID
);

#endif
5 changes: 5 additions & 0 deletions MsWheaPkg/HwhMenu/PlatformIDParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef PLATFORM_ID_PARSER_H_
#define PLATFORM_ID_PARSER_H_

/**
* Parses the Platform/Source ID
*
Expand All @@ -20,3 +23,5 @@ VOID
ParseSourceID (
IN CONST EFI_GUID *SourceID
);

#endif
5 changes: 5 additions & 0 deletions MsWheaPkg/Include/Library/CheckHwErrRecHeaderLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef CHECK_HW_ERR_REC_HEADER_LIB_H_
#define CHECK_HW_ERR_REC_HEADER_LIB_H_

/**
* Checks that all length and offset fields within the HWErrRec fall within the bounds of
* the buffer, all section data is accounted for in their respective section headers, and that
Expand All @@ -21,3 +24,5 @@ ValidateCperHeader (
IN CONST EFI_COMMON_ERROR_RECORD_HEADER *Err,
IN CONST UINTN Size
);

#endif

0 comments on commit e20fe27

Please sign in to comment.