.TH "cast" "" "" "Definition"
.PC
.PP
The
.I cast
operation \*(QLcoerces\*(QR a variable from one data type to another.
.PP
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 \fBhypot\fR takes two \fBdouble\fRs.
If the variables \fBleg_x\fR and \fBleg_y\fR are \fBfloat\fRs,
the rules of C require that they be cast automatically to \fBdouble\fR.
If the compiler did not
do not do this, \fBhypot\fR would grab a \fBdouble\fR's worth of memory:
the four bytes of your \fBfloat\fR, plus four bytes of whatever happens to
be sitting on the stack.
The leads to results that are less than totally accurate.
.PP
The other reason to cast a variable is when you cast one type of pointer
to another.
For example,
.DM
	char *foo;
	int *bar;
	bar = (int *)foo;
.DE
.PP
Although \fBfoo\fR and \fBbar\fR are of the same length, you would cast
.B foo
in this instance to stop the C compiler from complaining about
a type mismatch.
.SH "See Also"
.Xr "data formats," data_form
.Xr "data types," data_type
.Xr "Programming COHERENT" programmi
