Types Conversions
The mikroC PRO for PIC32 is a strictly typed language, with each operator, statement and function demanding appropriately typed operands/arguments. However, we often have to use objects of “mismatching” types in expressions. In that case, type conversion is needed.
Conversion of object of one type means that object's type is changed into another type. The mikroC PRO for PIC32 defines a set of standard conversions for built-in types, provided by compiler when necessary. For more information, refer to the Standard Conversions.
Conversion is required in the following situations:
- if a statement requires an expression of particular type (according to language definition), and we use an expression of different type,
- if an operator requires an operand of particular type, and we use an operand of different type,
- if a function requires a formal parameter of particular type, and we pass it an object of different type,
- if an expression following the keyword
return
does not match the declared function return type, - if intializing an object (in declaration) with an object of different type.
In these situations, compiler will provide an automatic implicit conversion of types, without any programmer's interference. Also, the programmer can demand conversion explicitly by means of the typecast operator. For more information, refer to the Explicit Typecasting.
What do you think about this topic ? Send us feedback!