Archived

This topic is now archived and is closed to further replies.

hehenoobhehe

Static Vs Dynamic Type Checking

Recommended Posts

My questions are: 1) What is static type checking? Does this mean that a programming language enforces the programmer to specify the variable type BEFORE running the program? 2)If indeed that is so, then, its called static because this rule is enforced NOT at run-time but at compile-time? 3) What is dynamic type checking? If its the opposite(wrong way to out things, I know.) of static, then does this mean that the type of the variable is checked at run-time? 4)If indeed that is so, then how''s this accomplished? Is it possible with C/C++ do to this? 5)Do C/C++ enforce static or dynamic type checking? 6)Last, what is the difference then between a strong/weak language from say one that enforces static/dynamic type checking? I know these questions are somewhat a bit unrelated and quite exhaustive, I would apreciate some online links/resources to expedite my understanding! Thanks in advance for your time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Static type checking is done at compile time.
Dynamic type checking is done at runtime.

Am I wrong?

Dynamic type checking can be emulated. VARIANTs for example, are checked dynamically based on a member that indicates the type.

Share this post


Link to post
Share on other sites
1) What is static type checking?

Static typing : variables have a type. Values can only be stored in a variable of the right type.

Does this mean that a programming language enforces the programmer to specify the variable type BEFORE running the program?

Yes.

2)If indeed that is so, then, its called static because this rule is enforced NOT at run-time but at compile-time?

Yes. The type of each variable is 'statically' defined in the source code, and does not depends on the 'dynamic' execution path.

3) What is dynamic type checking?

Dynamic typing : values have a type. Variables can hold any value. The 'type' of a variable is that of the value it is currently holding.

If its the opposite(wrong way to out things, I know.) of static, then does this mean that the type of the variable is checked at run-time?

Yes.

4)If indeed that is so, then how's this accomplished? Is it possible with C/C++ do to this?

Each value is accompanied by a type tag. Trying to do an operation that is invalid for a given type raises a run-time exception. In C++, polymorphic types give you some measure of dynamic typing, dynamic_cast and typeid let you do type checking. The 'type tag' in this case is (most often) the virtual function table pointer.

5)Do C/C++ enforce static or dynamic type checking?

They enforce static type checking. Polymorphic types must inherit from a common base class.

6)Last, what is the difference then between a strong/weak language from say one that enforces static/dynamic type checking?

In a strongly-typed language, there are no implicit type conversions. For example, in Ada, it is incorrect to assign an integer value to a real variable, and conversely.

I would apreciate some online links/resources to expedite my understanding!

Wiki
FOLDOC




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on July 28, 2003 2:52:48 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
I would apreciate some online links/resources to expedite my understanding!

Wiki
FOLDOC




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on July 28, 2003 2:52:48 PM]


Thanks for the answers but the online resources weren;t any great help because i couldnt get any search results on either wiki or foldoc!

Is there any useful article on this that you might have come across?

Share this post


Link to post
Share on other sites