Dynamic type checking

Discussion in 'C++' started by Vinodh Kumar P, Jun 14, 2004.

  1. Whenever I read any C++ literature I find the words "C++ is statically type
    checked".OK.Agreed.
    Is there any language that supports "Dynamic type checking"?
    In such a case any type can be assigned to any other type during compile
    time?
     
    Vinodh Kumar P, Jun 14, 2004
    #1
    1. Advertising

  2. "Vinodh Kumar P" <> schrieb im Newsbeitrag
    news:cajcdl$pnf$...
    > Whenever I read any C++ literature I find the words "C++ is

    statically type
    > checked".OK.Agreed.
    > Is there any language that supports "Dynamic type checking"?
    > In such a case any type can be assigned to any other type during

    compile
    > time?
    >


    Maybe inheritance or cast-operators would do? I mean - what do you
    expect when you assign a void* to a CMyClass?? See, you have to define
    it to get what you want.
    -Gernot
     
    Gernot Frisch, Jun 14, 2004
    #2
    1. Advertising

  3. Vinodh Kumar P

    Rolf Magnus Guest

    Vinodh Kumar P wrote:

    > Whenever I read any C++ literature I find the words "C++ is statically
    > type checked".OK.Agreed.
    > Is there any language that supports "Dynamic type checking"?


    Most scripting languages do.

    > In such a case any type can be assigned to any other type during
    > compile time?


    You variables might not even have a type at compile time since that type
    can change at run-time. So if you assign a variable to another one,
    that other variable changes its type accordingly.
    Consider python:

    x = 3 # x is an integer
    y = "Hello world" # y is a string
    x = y # now x is a string, too

    In C++, a variable can never change its type. You can however use
    polymorphism to get a more dynamic behaviour, within some limits.
     
    Rolf Magnus, Jun 14, 2004
    #3
  4. Vinodh Kumar P

    Pete C. Guest

    Rolf Magnus wrote:
    > Vinodh Kumar P wrote:
    >
    >> Whenever I read any C++ literature I find the words "C++ is
    >> statically type checked".OK.Agreed.
    >> Is there any language that supports "Dynamic type checking"?

    >
    > Most scripting languages do.
    >
    >> In such a case any type can be assigned to any other type during
    >> compile time?

    >
    > You variables might not even have a type at compile time since that
    > type can change at run-time. So if you assign a variable to another
    > one, that other variable changes its type accordingly.
    > Consider python:
    >
    > x = 3 # x is an integer
    > y = "Hello world" # y is a string
    > x = y # now x is a string, too
    >
    > In C++, a variable can never change its type. You can however use
    > polymorphism to get a more dynamic behaviour, within some limits.


    You can implement a VB6- style variant class, which I'm doing now. Of course
    on the inside you must use static type checking, but so does VB's variant.

    variant x = 3; // it's an int
    variant y = "hello"; // this one's a string
    x = y; // now it's a string too

    Mine so far supports that, and operator+, but I've got the basic framework
    done and it will be easy to do the rest of the operators. I'll post it here
    when I'm done.

    - Pete
     
    Pete C., Jun 14, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. heyo
    Replies:
    3
    Views:
    913
    Dan Pop
    Apr 1, 2004
  2. Tom Bradford
    Replies:
    4
    Views:
    628
    Florian Diesch
    Mar 10, 2006
  3. Delaney, Timothy (Tim)

    RE: Type Hinting vs Type Checking and Preconditions

    Delaney, Timothy (Tim), Mar 7, 2006, in forum: Python
    Replies:
    7
    Views:
    476
    Paul Boddie
    Mar 8, 2006
  4. Tom Bradford
    Replies:
    3
    Views:
    395
    Alex Martelli
    Mar 9, 2006
  5. Randell D.
    Replies:
    12
    Views:
    257
    Randell D.
    Jul 6, 2005
Loading...

Share This Page