Tutorial by Examples: conversions

Given that the function has a proper prototype, integers are widened for calls to functions according to the rules of integer conversion, C11 6.3.1.3. 6.3.1.3 Signed and unsigned integers When a value with integer type is converted to another integer type other than _Bool, if the value can be r...
Pointer conversions to void* are implicit, but any other pointer conversion must be explicit. While the compiler allows an explicit conversion from any pointer-to-data type to any other pointer-to-data type, accessing an object through a wrongly typed pointer is erroneous and leads to undefined beh...
Beware that numbers can accidentally be converted to strings or NaN (Not a Number). JavaScript is loosely typed. A variable can contain different data types, and a variable can change its data type: var x = "Hello"; // typeof x is a string x = 5; // changes typeof x to...
Explicit casting operators can be used to perform conversions of numeric types, even though they don't extend or implement one another. double value = -1.1; int number = (int) value; Note that in cases where the destination type has less precision than the original type, precision will be lost....
[<Measure>] type m // meters [<Measure>] type cm // centimeters // Conversion factor let cmInM = 100<cm/m> let distanceInM = 1<m> let distanceInCM = distanceInM * cmInM // 100<cm> // Conversion function let cmToM (x : int<cm>) = x / 100<cm/m> l...
Converting an integer type to the corresponding promoted type is better than converting it to some other integer type. void f(int x); void f(short x); signed char c = 42; f(c); // calls f(int); promotion to int is better than conversion to short short s = 42; f(s); // calls f(short); exact mat...
Conversion SpecifierType of ArgumentDescriptioni, dintprints decimaluunsigned intprints decimalounsigned intprints octalxunsigned intprints hexadecimal, lower-caseXunsigned intprints hexadecimal, upper-casefdoubleprints float with a default precision of 6, if no precision is given (lower-case used f...
The result of a reinterpret_cast from one function pointer type to another, or one function reference type to another, is unspecified. Example: int f(); auto fp = reinterpret_cast<int(*)(int)>(&f); // fp has unspecified value C++03 The result of a reinterpret_cast from one object poi...
static_cast can convert from an integer or floating point type to an enumeration type (whether scoped or unscoped), and vice versa. It can also convert between enumeration types. The conversion from an unscoped enumeration type to an arithmetic type is an implicit conversion; it is possible, but ...
Scala offers implicit conversions between all the major collection types in the JavaConverters object. The following type conversions are bidirectional. Scala TypeJava TypeIteratorjava.util.IteratorIteratorjava.util.EnumerationIteratorjava.util.IterableIteratorjava.util.Collectionmutable.Bufferjav...
Descriptor objects can allow related object attributes to react to changes automatically. Suppose we want to model an oscillator with a given frequency (in Hertz) and period (in seconds). When we update the frequency we want the period to update, and when we update the period we want the frequency ...
╔═══════════╦════════════╦═══════════════════════════════════════════════════════════════════╗ ║ From ║ To ║ Example ║ ╠═══════════╬════════════╬═══════════════════════════════════════════════════════════════════╣ ║String ...

Page 1 of 1