Type safety could prevent nuclear war
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 4 16:20:02 PST 2016
On Friday, 5 February 2016 at 00:12:07 UTC, Ola Fosheim Grøstad
wrote:
> It makes perfect sense for one compilation unit to type a
> parameter pointer to float and another unit to type the same
> parameter as a simd-array of floats. The underlying code could
> be machine language. And in machine language there are no types
> (on current CPUs), only bit patterns. So you can have multiple
> reasonable interpretations of the same machine language entry.
>
> A type is a constraint, but it isn't a property of the actual
> bits, it is a language specific interpretation.
Aliasing types like that can be useful sometimes, but only within
certain limits. In particular, the size (with alignment padding)
of the types in question must match, otherwise you will corrupt
the stack.
It is often useful to cast from one pointer type to another, but
that is why C has void* and explicit casts - so that one may
document that the reinterpretation is intentional.
More information about the Digitalmars-d
mailing list