Ad Code

Implicit and Explicit Type of Conversion

Implicit Type Conversions

  • A widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type.
  • A narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int.
  • A mixed-mode expression is one that has operands of different types.
  • Coercion is an implicit type conversion.

Explicit Type Conversions

  • Called casting in C-based language

Examples

  • C: (int) angle
  • Ada: Float (sum)

Note: that Ada’s syntax is similar to function calls

Disadvantage of coercion:

  • They decrease in the type error detection ability of the compiler.
  • In most languages, all numeric types are coerced in expressions, using widening conversions.
  • In Ada, there are virtually no coercion in expressions
Reactions

Post a Comment

0 Comments