Niklaus Wirth on this topic in A Plea for Lean Software:
Without type checking, the notion of abstraction in programming remains hollow and academic. Abstraction can work only with languages that postulate strict, static typing of every variable and function. In this respect, C fails – it resembles assembler code, where “everything goes”.
[…]
To be worthy of the description, an object-oriented language must embody strict, static typing that cannot be breached, whereby programmers can rely on the compiler to identify inconsistencies.
[…]
The exclusive use of a strongly typed language was the most influential factor in designing this complex system in such a short time. […] Static typing (a) lets the compiler pinpoing inconsistencies before program execution; (b) lets the designer change definitions of structures with less danger of negatice consequences; and (c) speeds up the improvement process, which could include changes that might not otherwise be considered feasible.
Niklaus Wirth in Good Ideas, Through the Looking Glass:
One of the worst features ever is the loophole. This author makes this statement with a certain amount of tongue in cheek and uneasiness, because he infected his languages Pascal, Modula, and even Oberon with this deadly virus.
The loophole lets the programmer breach the type-checking by the compiler. It is a way to say: “Don’t interfere, as I am smarter than the rules”. Loopholes take many forms. The most common are explicit type transfer function, such as
x := LOOPHOLE[i,REAL] Mesa x := REAL(i) Modula x := SYSTEM.VAL(REAL,i) Oberon
But they can also be disguised as absolute address specifications, or by variant records in Pascal. In the examples above, the internal representation of integer i is to be interpreted as a floating-point (real) number. This can only be done with knowledge about number representation, which should not be necessary when dealing with the abstraction level provided by the language. […], but the loophole is nevertheless a bad idea.
In Fortran the loopholes would be equivalence
or the transfer
function.
Whether the complex to real conversion or association presents a loophole is up to debate. I think the way @everythingfunctional has shown is quite clean. Unfortunately, I don’t see how it would help in @PierU’s second case, when the buffer is real.