COHERENT manpages

This page displays the COHERENT manpage for cast [Definition].

List of available manpages
Index


cast -- Definition

The cast operation ``coerces'' a variable from one data type to another.

There  are two  reasons to  cast  a variable.   The first  is to  convert a
variable's data  into a form acceptable to a  given function.  For example,
the function hypot takes two doubles.  If the variables leg_x and leg_y are
floats, the rules  of C require that they be  cast automatically to double.
If the compiler  did not do not do this,  hypot would grab a double's worth
of  memory: the  four bytes  of  your float,  plus four  bytes of  whatever
happens to  be sitting on  the stack.  The  leads to results  that are less
than totally accurate.

The other reason to cast a variable is when you cast one type of pointer to
another.  For example,

    char *foo;
    int *bar;
    bar = (int *)foo;

Although foo  and bar are  of the same  length, you would cast  foo in this
instance to stop the C compiler from complaining about a type mismatch.

See Also

data formats,
data types,
Programming COHERENT