I have this piece of code :
with Ada.Unchecked
private package MyPackage is
function UC_Bool_To_U8 is new Ada.Unchecked_Conversion (Source => Boolean, Target => T_U8);
end MyPackage;
Where T_U8 is :
type T_U8 is range 0 .. 2**7;
Function UC_Bool_To_U8 is working but I have warnings on compilation :
warning: types for unchecked conversion have different sizes
warning: size of "Boolean" is 1, size of "T_U8" is 8
warning: source will be extended with 7 high order zero bits
How can I suppress theses warnings ?
Warnings can be suppressed by using a pragma as shown in this Ada Gem blog post and the following example:
main.adb
However, please also consider to not use
Unchecked_Conversionwhen converting a boolean type to some integer or modular type. The compiler will completely optimize away a simpleif-statement as can be seen in the Compiler Explorer:input to Compiler Explorer
ouput of Compiler Explorer (using compiler switch
-O1or-O2)