Type conversions

An expression of a given type is implicitly converted when it is used in the following situations:
  • As an operand of an arithmetic or logical operation.
  • As a condition in an if statement or an iteration statement (such as a for loop). The expression will be converted to a Boolean (or an integer in C89).
  • In a switch statement. The expression is converted to an integral type.
  • As the right operand of an assignment or as an initializer.
  • As an initialization. This includes the following types:
    • A function is provided an argument value that has a different type than the parameter.
    • The value specified in the return statement of a function has a different type from the defined return type for the function.

C onlyThe implicit conversion result is an rvalue.C only

C++ onlyThe implicit conversion result belongs to one of the following value categories depending on different converted expressions types:
  • An lvalue if the type is an lvalue reference type C++11 onlyor an rvalue reference to a function typeC++11 only
  • C++11 onlyAn xvalue if the type is an rvalue reference to an object typeC++11 only
  • A C++11 only(prvalue)C++11 only rvalue in other cases
C++ only

You can perform explicit type conversions using a cast expression, as described in Cast expressions.

Vector type casts (IBM extension)

Vector types can be cast to other vector types. The cast does not perform a conversion: it preserves the 128-bit pattern, but not necessarily the value. A cast between a vector type and a scalar type is not allowed.

Vector pointers and pointers to non-vector types can be cast back and forth to each other. When a pointer to a non-vector type is cast to a vector pointer, the address should be 16-byte aligned. The referenced object of the pointer to a non-vector type can be aligned on a 16-byte boundary by using either the __align type qualifier or __attribute__((aligned(16))).



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us