As I know that in C, we can use function pointer and this is called during run-time (1).
By definition from wikipedia:
Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all ...
So my que开发者_运维知识库stion is, why C is not a dynamic language providing the feature in (1) ?
Because the function in your function pointer is still compiled at compile time.
You cannot add a new function or modify a function "on the fly" at runtime.
Polymorphic behavior does not a dynamic language make. Generally speaking, someone referring to a "dynamic language" is referring to it's type system. PHP is a dynamic language, because any variable can contain any kind of data, and conversions between data types are handled implicitly. The determination of what and when to convert is made at run time.
Also, I think C fails the "class of high level programming languages" portion of the definition you cite.
You can only assign a pointer to a function that exists at compile-time. You can not compile a new function in the middle of a C program and assign a pointer to that function.
A language is usually considered dynamic because of its type system. C is statically typed. This means that every variable has a type assigned to it at creation and that type cannot change. You cannot put float data into an int pointer*. In a dynamic language like Python, data has a type but variables do not. I can assign a string to the same variable as I assign an integer to.
The definition you refer to also seems to talk about dynamic programming, that is adding code at runtime. In C it is impossible, without thinking in terms of assembly, to add new code after compilation time. Your program cannot decide that it needs a new function while it is executing. In a language like Scheme, it can.
*Casting doesn't count because you are explicitly converting the type.
C is not a high-level language, it is very low level.
It lacks classes and other high level features and instead offers direct bit-flipping and the ability to manipulate memory directly.
Typically, dynamic languages run on top of some VM, such as the JVM or the CLR, are interpreted, a la Python, or use an executable stack, i.e. Haskell, to provide functionality. In contrast, C is compiled directly to machine code.
There are ways to make C self-modify, but that is a very difficult technique and doesn't really qualify as a "dynamic language."
精彩评论