0

I wonder if type erasing techniques are used anywhere in C language. What happens in C, when type casting is done? Does it use concepts similar to type erasure and down casting?

What are the main difference between type erasure and type casting?

NaveeNeo
  • 205
  • 3
  • 13
  • 1
    C doesn't have any latent types, so there's nothing to erase. – Barmar Nov 22 '16 at 19:49
  • Here is a [`C++` question](http://stackoverflow.com/questions/6089498/type-erasure-for-methods-with-differing-in-return-types) FYI. – Weather Vane Nov 22 '16 at 19:50
  • What is the main difference between type erasure and casting? – NaveeNeo Nov 22 '16 at 20:11
  • @NaveeNeo They're totally different concepts. Type erasure refers to whether the type information exists in the runtime data. C data doesn't have type information. Casting is converting an object from one type to another. – Barmar Nov 22 '16 at 20:25
  • 1
    It is a technique to implement generic code. Far, far removed from what C can do. I suppose *typedef* could qualify somewhat. Eh, you'll have to have a lot of imagination. Let it run, run, no. – Hans Passant Nov 22 '16 at 22:19

1 Answers1

1

Are you a Java developer?
If yes you need to forget a LOT of things and learn another LOT.

Down casting means inheritance. So this is not C.

C can cast almost anything to anything (C assumes that you know what you are doing, contrary to Java, C# and others)

Type erasure is a Java concept because JRE doesn't have generics at run-time, only raw-types.

In C you have only binary code at run-time, just like in Assembly and that's all we need to have lightning-fast executables (remember that almost any compiler, framework or virtual machine is built in C or C++).

In C there is no such thing of RTTI (Run-Time Type Information) and we don't need this because the aim of C is program directly over the metal.

user7140484
  • 920
  • 6
  • 14