next up previous
Next: Constraints on operators Up: The C type system Previous: Types


Conversions

Section 6.2 of the standard describes the relationships between types that are engendered by implicit conversions. Such implicit conversions are defined in OIL by coercions.

Implicit conversions between derived types can only be defined after the types themselves are defined. Thus coercions involving derived types must be components of the relevant OIL classes. These coercions are defined here as macros that are invoked as components of the classes defined in Section 4.1.1.

Integral promotions[13]:

COERCION
  CChartoInt          (TypeIs_char):           TypeIs_int;
  CUnsignedChartoInt  (TypeIs_unsigned_char):  TypeIs_int;
  CShorttoInt         (TypeIs_short):          TypeIs_int;
  CUnsignedShorttoInt (TypeIs_unsigned_short): TypeIs_int;
This macro is invoked in definition 4.

Usual arithmetic conversions[14]:

COERCION
  CDoubletoLongDouble (TypeIs_double):         TypeIs_long_double;
  CFloattoDouble      (TypeIs_float):          TypeIs_double;
  CUnsignedLongtoFloat(TypeIs_unsigned_long):  TypeIs_float;

  CLongtoUnsignedLong (TypeIs_long):           TypeIs_unsigned_long;
  CUnsignedInttoLong  (TypeIs_unsigned_int):   TypeIs_long;
  CInttoLong          (TypeIs_int):            TypeIs_long;
  CInttoUnsignedInt   (TypeIs_int):            TypeIs_unsigned_int;
This macro is invoked in definition 4.

Certain operators require that the integral promotion be performed on their operand(s), and the result has the promoted type. These operators are therefore defined in terms of sets that include only promoted integer types:

Types[15]:

SET TypeIs_IntegralPromoted =
  [TypeIs_int, TypeIs_unsigned_int, TypeIs_long, TypeIs_unsigned_long];

SET TypeIs_ArithPromoted    =
  TypeIs_IntegralPromoted + TypeIs_Floating;
This macro is defined in definitions 5, 10, 11, 12, and 15.
This macro is invoked in definition 4.

A conditional can accept any scalar type. Thus we need a type key representing any scalar type:

Define a scalar type[16]:

COERCION (TypeIs_Scalar):scalarType;
This macro is invoked in definition 4.

Section 6.2.2.1 of the standard says that an lvalue that has type ``array of type'' is converted to an expression that has type ``pointer to type'' except when it is the operand of sizeof or the unary & operator, or is a character string literal used to initialize an array. A function designator of type ``function returning type'' is converted to an expression that has type `pointer to function returning type'' under similar circumstances:

Section 6.2.2.2 says that an expression occurs in a context where a void expression is required, its value or designator is discarded.

void[17]:

COERCION CScalartoVoid   (TypeIs_Scalar):   TypeIs_void;
This macro is invoked in definition 4.

Section 6.2.2.3 of the standard describes the conversions among pointers. TypeIs_NULL represents an integral constant expression with the value 0, which can be converted to a pointer of any type.

CNulltoVoidPtr is required because it is possible to use an integral constant expression with the value 0 as a value of type void* directly, and CNulltoIntegral is required to allow an integral constant expression with the value 0 to be interpreted as an integral value rather than a null pointer.

The null pointer constant[18]:

COERCION
  (TypeIs_NULL): TypeIs_Integral;
OPER
  CNulltoVoidPtr (TypeIs_NULL): TypeIs_VoidPointer;
INDICATION
  Cast_Indication: CNulltoVoidPtr;
This macro is invoked in definition 4.


next up previous
Next: Constraints on operators Up: The C type system Previous: Types
2008-08-30