ABL electronic PIC16 Personal Computer User Manual


 
The result of the expression is the same type as that of the two operands.
Here are several examples of implicit conversion:
2+3.1
// = 2. + 3.1 = 5.1
5/4*3.
// = (5/4)*3. = 1*3. = 1.*3. = 3.0
3.*5/4
// = (3.*5)/4 = (3.*5.)/4 = 15./4 = 15./4. = 3.75
Pointer Conversions
Pointer types can be converted to other pointer types using the typecasting mecha-
nism:
char *str;
int *ip;
str = (char *)ip;
More generally, the cast (
type
*) will convert a pointer to type “pointer to
type
”.
Explicit Types Conversions (Typecasting)
In most situations, compiler will provide an automatic implicit conversion of types
where needed, without any user interference. Also, you can explicitly convert an
operand to another type using the prefix unary typecast operator:
(
type
)
object
For example:
char a, b;
/* Following line will coerce a to unsigned int: */
(unsigned int) a;
/* Following line will coerce a to double,
then coerce b to double automatically,
resulting in double type value: */
(double) a + b;
// equivalent to ((double) a) + b;
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
84
MikroElektronika:
Development
tools
-
Books
-
Compilers
page