4.1.1 Type Checking

Some compilers perform stronger type checking than other compilers such as the Intel family of compilers including the Intel(R) C Compiler for EFI Byte Code. As a result, code that compiles without any errors or warnings on one compiler may generate warnings or errors when compiled with another compiler. The following example shows two common examples from UEFI Drivers that use AllocatePool() and OpenProtocol().

These examples show the style that may generate warnings with some compilers, and the correct method to prevent the warnings.

Example 7-Stronger type checking

#include <Uefi.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DriverBinding.h>
#include <Library/UefiBootServicesTableLib.h>
typedef struct {
UINT8 First;
UINT32 Second;
} MY_STRUCTURE;
EFI_STATUS Status;
EFI_DRIVER_BINDING_PROTOCOL *This;
EFI_HANDLE ControllerHandle;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
MY_STRUCTURE *MyStructure;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
&BlockIo, // Compiler warning
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo, // No compiler warning
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (MY_STRUCTURE),
&MyStructure // Compiler warning
);
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (MY_STRUCTURE),
(VOID **)&MyStructure // No compiler warning
);