type cast in c compiler -


consider following example mixed mode expression supported: c = + b*10.5 a , b integers , c float. describe how data typecast appropriate format

you need 'usual arithmetic conversions' in text book, or in c standard (§6.3.1.8 in c11 — iso/iec 9899:2011), reads:

6.3.1.8 usual arithmetic conversions

1 many operators expect operands of arithmetic type cause conversions , yield result types in similar way. purpose determine common real type operands , result. specified operands, each operand converted, without change of type domain, type corresponding real type common real type. unless explicitly stated otherwise, common real type corresponding real type of result, type domain type domain of operands if same, , complex otherwise. pattern called usual arithmetic conversions:

first, if corresponding real type of either operand long double, other operand converted, without change of type domain, type corresponding real type long double.

otherwise, if corresponding real type of either operand double, other operand converted, without change of type domain, type corresponding real type double.

otherwise, if corresponding real type of either operand float, other operand converted, without change of type domain, type corresponding real type float.62)

otherwise, integer promotions performed on both operands. following rules applied promoted operands:

if both operands have same type, no further conversion needed.

otherwise, if both operands have signed integer types or both have unsigned integer types, operand type of lesser integer conversion rank converted type of operand greater rank.

otherwise, if operand has unsigned integer type has rank greater or equal rank of type of other operand, operand signed integer type converted type of operand unsigned integer type.

otherwise, if type of operand signed integer type can represent of values of type of operand unsigned integer type, operand unsigned integer type converted type of operand signed integer type.

otherwise, both operands converted unsigned integer type corresponding type of operand signed integer type.

2 values of floating operands , of results of floating expressions may represented in greater range , precision required type; types not changed thereby.63)

62) example, addition of double _complex , float entails conversion of float operand double (and yields double _complex result).

63) cast , assignment operators still required remove range , precision.

and integer promotions defined in §6.3.1.1:

6.3.1.1 boolean, characters, , integers

1 every integer type has integer conversion rank defined follows:

  • no 2 signed integer types shall have same rank, if have same representation.
  • the rank of signed integer type shall greater rank of signed integer type less precision.
  • the rank of long long int shall greater rank of long int, shall greater rank of int, shall greater rank of short int, shall greater rank of signed char.
  • the rank of unsigned integer type shall equal rank of corresponding signed integer type, if any.
  • the rank of standard integer type shall greater rank of extended integer type same width.
  • the rank of char shall equal rank of signed char , unsigned char.
  • the rank of _bool shall less rank of other standard integer types.
  • the rank of enumerated type shall equal rank of compatible integer type (see 6.7.2.2).
  • the rank of extended signed integer type relative extended signed integer type same precision implementation-defined, still subject other rules determining integer conversion rank.
  • for integer types t1, t2, , t3, if t1 has greater rank t2 , t2 has greater rank t3, t1 has greater rank t3.

2 following may used in expression wherever int or unsigned int may used:

  • an object or expression integer type (other int or unsigned int) integer conversion rank less or equal rank of int , unsigned int.
  • a bit-field of type _bool, int, signed int, or unsigned int.

if int can represent values of original type (as restricted width, bit-field), value converted int; otherwise, converted unsigned int. these called integer promotions.58) other types unchanged integer promotions.

3 integer promotions preserve value including sign. discussed earlier, whether ‘‘plain’’ char treated signed implementation-defined.

58) integer promotions applied only: part of usual arithmetic conversions, argument expressions, operands of unary +, -, , ~ operators, , both operands of shift operators, specified respective subclauses.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -