|
|
coherent
cast Definition cast
The cast operation ``coerces'' a variable from one data type to
another.
There are two reasons to cast a variable. The first is to con-
vert a variable's data into a form acceptable to a given func-
tion. For example, the function hhyyppoott takes two ddoouubbllees. If the
variables lleegg_xx and lleegg_yy are ffllooaatts, the rules of C require that
they be cast automatically to ddoouubbllee. If the compiler did not do
not do this, hhyyppoott would grab a ddoouubbllee's worth of memory: the
four bytes of your ffllooaatt, 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 ffoooo and bbaarr 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, definitions
COHERENT Lexicon Page 1
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.