是C强类型? [英] Is C strongly typed?

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

问题描述

要报价维基百科

两种常用的语言是
  支持多种隐
  转换是C和C ++,并且它是
  有时声称,这些都是
  弱类型语言。然而,
  其他人则认为这些语言
  放在怎么够限制
  不同类型的操作数可以是
  混合,这两个应被视为
  作为强类型语言。

Two commonly used languages that support many kinds of implicit conversion are C and C++, and it is sometimes claimed that these are weakly typed languages. However, others argue that these languages place enough restrictions on how operands of different types can be mixed, that the two should be regarded as strongly typed languages.

有没有更确切的答案?

推荐答案

强类型和弱类型是没有广泛商定的技术含义条款。这确实有一个明确的含义的术语

"Strongly typed" and "weakly typed" are terms that have no widely agreed-upon technical meaning. Terms that do have a well-defined meaning are


  • 动态类型表示类型的连接在运行时的值,并混合不同类型的值的尝试可能会导致运行时类型的错误。例如,如果在计划试图通过编写添加一个为真(+ 1 #T)这将导致一个错误。你遇到的错误只有当你试图执行违规code。

  • Dynamically typed means that types are attached to values at run time, and an attempt to mix values of different types may cause a "run-time type error". For example, if in Scheme you attempt to add one to true by writing (+ 1 #t) this will cause an error. You encounter the error only if you attempt to execute the offending code.

静态类型表示类型在编译期进行检查,而且没有一个静态类型的程序被编译器拒绝。例如,如果在ML试图通过编写添加一个为真 1 +真,该方案将与(可能是神秘的)错误信息被拒绝。你总是即使可能永远不会被执行code中的错误。

Statically typed means that types are checked at compile time, and a program that does not have a static type is rejected by the compiler. For example, if in ML you attempt to add one to true by writing 1 + true, the program will be rejected with a (probably cryptic) error message. You always get the error even if the code might never be executed.

不同的人preFER不同的系统部分按多少,他们看重的灵活性和多少,他们担心运行时错误。

Different people prefer different systems according in part to how much they value flexibility and how much they worry about run-time errors.

有时,强类型是松散用来表示静态类型和弱类型使用不当的意思是动态类型。对于长期更好地利用强类型是,则不能变通解决或颠覆式制度,而弱类型的意思是在类型系统漏洞。有悖常理的是,与静态类型系统的大多数语言都有漏洞,而动态类型系统的许多语言没有漏洞。

Sometimes "strongly typed" is used loosely to mean "statically typed", and "weakly typed" is used incorrectly to mean "dynamically typed". A better use for the term "strongly typed" is that "you cannot work around or subvert the type system", whereas "weakly typed" means "there are loopholes in the type system". Perversely, most languages with static type systems have loopholes, while many languages with dynamic type systems have no loopholes.

这些术语没有被连接在与一个语言的隐式转换的数量的任何方式。

None of these terms are connected in any way with the number of implicit conversions available in a language.

如果你想谈论precisely有关的编程语言,最好避免术语强类型和弱类型。我会说C是静态类型语言,但有很多漏洞。其中一个漏洞是,你可以随意施放任何指针类型到任何其他指针类型。您也可以通过宣称有两个成员,每个问题的类型的一个C联合创建任何两种类型你选择之间的漏洞。

If you want to talk precisely about programming languages, it is best to avoid the terms "strongly typed" and "weakly typed". I would say that C is a language that is statically typed but that has a lot of loopholes. One loophole is that you can freely cast any pointer type to any other pointer type. You can also create a loophole between any two types of your choice by declaring a C union that has two members, one for each of the types in question.

我已经写了更多关于静态和动态类型的<一个href=\"http://stackoverflow.com/questions/376611/why-inter$p$pted-langs-are-mostly-ducktyped-while-compiled-have-strong-typing#376828\">why-inter$p$pted-langs-are-mostly-ducktyped-while-compiled-have-strong-typing.

I have written more about static and dynamic typing at why-interpreted-langs-are-mostly-ducktyped-while-compiled-have-strong-typing.

这篇关于是C强类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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