casts and puns (and digressions...)
Dick Dunn
rcd at opus.UUCP
Wed Nov 7 20:39:39 AEST 1984
> ... Do not be misled by the fact that some casts on some machines
> generate no code. A cast is a *conversion*, not a type pun...
Unfortunately, not entirely true. What C calls "casts" covers both
true casts (in, say, the ALGOL 68 sense) and puns, at least in practice.
The operation is a cast when conversion "makes sense" (in semantic terms);
otherwise it's a pun. For example, if i is an integer, (float)i is clearly
a cast; it generates instructions on most machines and produces a different
internal datum which is the float corresponding most closely to the
integral value of i. However, (long*)i is a pun; you just have to stretch
too far to make any sensible semantics which makes it a true cast.
> >example 'struct foo {struct foo *ref;};'...
> struct foo is not a recursive type. At best you might call it an
> iterative type. What would you think of struct foo {struct foo bar;}; ?
Please be careful when attacking other folks' terminology. Structured
types which contain references to themselves are quite commonly called
"recursive". (See, for example, Hoare's seminal paper "Notes on Data
Structuring".)
> >Also, Pascal, which is doubtlessly a strongly typed language, does
> >permit a type definition like 'type ref= ^ref;' and handles it
> >correctly...
Perhaps true, but marginally relevant to reality, since the only value
assignable to an object of type ref is NIL.
--
Dick Dunn {hao,ucbvax,allegra}!nbires!rcd (303)444-5710 x3086
...Never attribute to malice what can be adequately explained by stupidity.
More information about the Comp.lang.c
mailing list