900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 静态类型/动态类型/强类型/弱类型

静态类型/动态类型/强类型/弱类型

时间:2024-01-13 14:45:15

相关推荐

静态类型/动态类型/强类型/弱类型

C/C++是弱类型,并且是静态类型,因为可以容忍隐式类型转换,并且可以进行强制类型转换,然后编译的时候就已经直到变量的类型,所以是静态类型(类型错误引发的是语法错误)

python是动态类型,强类型,偏向于不容忍隐式类型转换。

wiki上关于强类型:

Java, Pascal, Ada and C require all variables to have a declared type, and support the use of explicit casts of arithmetic values to other arithmetic types. Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows pointer values to be explicitly cast while Java and Pascal do not.Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java virtual machine’s type system**. C# and are similar to Java in that respect**, though they allow disabling of dynamic type checking by explicitly putting code segments in an “unsafe context”. Pascal’s type system has been described as “too strong”, because the size of an array or string is part of its type, making some programming tasks very difficult.[7]

Smalltalk, Perl, Ruby, Python, and Self are all “strongly typed” in the sense that typing errors are prevented at runtime and they do little implicit type conversion, but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules.The term duck typing is now used to describe the dynamic typing paradigm used by the languages in this group.

The Lisp family of languages are all “strongly typed” in the sense that typing errors are prevented at runtime.Some Lisp dialects like Common Lisp or Clojure do support various forms of type declarations[8] and some compilers (CMUCL[9] and related) use these declarations together with type inference to enable various optimizations and also limited forms of compile time type checks.

Standard ML, F#, OCaml, Haskell, and Rust are statically type-checked, but the compiler automatically infers a precise type for most values.

Visual Basic is a hybrid language.In addition to variables with declared types, it is also possible to declare a variable of “Variant” data type that can store data of any type. Its implicit casts are fairly liberal where, for example, one can sum string variants and pass the result into an integer variable. Visual Basic is weakly typed.

Assembly language and Forth have been said to be untyped.There is no type checking; it is up to the programmer to ensure that data given to functions is of the appropriate type. Any type conversion required is explicit.

wiki 上的 Type system

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。