strong/weak typing and pointers

Duncan Booth duncan.booth at invalid.invalid
Fri Oct 29 10:50:49 CEST 2004


Gabriel Zachmann wrote:

> Is it correct to say that strong/weak typing does not make a
> difference if one does not use any pointers (or adress-taking
> operator)? 
> 
> More concretely, I am thinking particularly of Python vs C++.
> So, are there any examples (without pointers, references, or
> adress-taking), which would have a different result in Python and in
> C++? 

Here's a trivial example that is almost identical in Python and C/C++ but 
gives totally different results. In a weakly typed language such as C or 
C++:

#include <stdio.h>

int main(int argc, char**argv)
{
    float f = 3;
    printf("value is %d", f);
}

I get the output (you may get different results):

value is 0

In a fairly strongly typed language such as Python:

>>> f = 3.0
>>> print "value is %d" % f
value is 3

In a really strongly typed language I would expect an exception to 
be thrown.



More information about the Python-list mailing list