I have the following code:
//#include "stdint.h"
#include "uefi.h"
//#include "efi_libs.h"
void PrintLn(CHAR16* String, EFI_SYSTEM_TABLE* _SystemTable);
void Print(CHAR16* String, EFI_SYSTEM_TABLE* _SystemTable);
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* _SystemTable)
{
// SystemTable = _SystemTable;
_SystemTable->ConOut->Reset(_SystemTable->ConOut, 1);
_SystemTable->ConIn->Reset(_SystemTable->ConIn, 1);
_SystemTable->ConOut->SetAttribute(_SystemTable->ConOut, EFI_GREEN);
Print(L"Welcome", _SystemTable);
PrintLn(L"Press any key to continue...", _SystemTable);
EFI_INPUT_KEY key;
while (_SystemTable->ConIn->ReadKeyStroke(_SystemTable->ConIn, &key) == EFI_NOT_READY);
return EFI_SUCCESS;
}
void Print(CHAR16* String, EFI_SYSTEM_TABLE* _SystemTable)
{
_SystemTable->ConOut->OutputString(_SystemTable->ConOut, String);
}
void PrintLn(CHAR16* String, EFI_SYSTEM_TABLE* _SystemTable)
{
_SystemTable->ConOut->OutputString(_SystemTable->ConOut, String);
_SystemTable->ConOut->OutputString(_SystemTable->ConOut, L"\r\n");
}
And I am getting this warning when compiling it:
src/efi_main.c:17:8: warning: passing 'unsigned short[8]' to parameter of type 'CHAR16 *' (aka 'short *') converts between pointers to integer types with different sign [-Wpointer-sign] Print(L"Welcome", _SystemTable); ^~~~~~~~~~ src/efi_main.c:7:20: note: passing argument to parameter 'String' here void Print(CHAR16* String, EFI_SYSTEM_TABLE* _SystemTable); ^
Now it has been many years since I wrote ANSI C, and I have no idea how to eradicate the warning, can someone please explain the warning to me and show me how t fix it?
Your
Printaccepts a pointer to aCHAR16i.e.shorti.e.signed short. However,L"Welcome"produces a pointer to awchar_ti.e.unsigned short. So you attempt to pass anunsigned short *into asigned short *argument, hence the warning.The solution is therefore to either change the string-related functions to accept
wchar_t *instead ofCHAR16 *arguments (which would make sense given thatLstring literals emit awchar_t[]) or to change the typedef ofCHAR16to be compatible by making itunsignedinstead ofsigned.