Reputation: 21
Could anyone please explain me the operation of ada.unchecked_coversion(float, UnsignedInteger). What this operation will be performed ? Could anyone please clarify this with example. Thanks a lot in advance.
Upvotes: 1
Views: 290
Reputation: 3358
Normally an unchecked conversion has no effect at run time. It does not result in any code being generated. It is just permission to the compiler to interpret the bytes of the source value as the representation of a value of the target type. Most importantly, it does not cause a copy.
Upvotes: 2
Reputation:
From here
An unchecked conversion is a bit-for-bit copy without regard to the meanings attached to those bits and bit positions by either the source or the destination type. The source bit pattern can easily be meaningless in the context of the destination type. Unchecked conversions can create values that violate type constraints on subsequent operations. Unchecked conversion of objects mismatched in size has implementation-dependent results.
So it should be used with care and only for types that have "same" bit representation. e.g it wouldn't probably work to cast float to int as those types could be represented differently in memory.
Here are two variables
before conversion
and after calling unchecked conversion
As you can see whole operation is just bit by bit copy of source variable to target variable
Hope this answers your questions
Upvotes: 6