什么是类型安全,什么是"类型安全"备择方案? [英] What is type safety and what are the "type safe" alternatives?

查看:133
本文介绍了什么是类型安全,什么是"类型安全"备择方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:结果
  什么是类型安全的?结果
  什么是类型安全?

我读到关于C ++的载体,它提到,的memcpy 的printf 从C函数不是类型安全。文章在这里:<一href=\"http://en.wikipedia.org/wiki/Vector_%28C%2B%2B%29\">http://en.wikipedia.org/wiki/Vector_(C%2B%2B).

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?

推荐答案

键入安全意味着编译器可以检查是否使用正确的类型。例如,如果你使用的printf ,你可以不小心被写这个程序崩溃:

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);

,因为42是一个整数,而不是字符串。

because 42 is an integer, not a string.

这篇关于什么是类型安全,什么是&QUOT;类型安全&QUOT;备择方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆