What is type safety and what are the "type safe" alternatives?

Dr Deo picture Dr Deo · Jan 26, 2010 · Viewed 26.1k times · Source

Possible Duplicates:
What is Type-safe?
What is type-safety?

I was reading about c++ vectors and it was mentioned that memcpy and printf functions from C are not type safe. Article here: http://en.wikipedia.org/wiki/Vector_(C%2B%2B).

Question: In simple English, what is type safety and what are the "type safe" alternatives?

Answer

Chris Jester-Young picture Chris Jester-Young · Jan 26, 2010

Type safety means that the compiler can check whether you're using the right types. For example, if you're using printf, you could accidentally crash your program by writing this:

printf("The meaning of life is %s", 42);

because 42 is an integer, not a string.