Why is python not written in C++ ?

John Bokma john at castleamber.com
Tue Aug 3 11:29:35 CEST 2010

Carl Banks <pavlovevidence at gmail.com> writes:

> On Aug 1, 6:09 pm, John Bokma <j... at castleamber.com> wrote:
>> Roy Smith <r... at panix.com> writes:
>> > In article <4c55fe82$0$9111$426a3... at news.free.fr>,
>> >  candide <cand... at free.invalid> wrote:
>> >> Python is an object oriented langage (OOL). The Python main
>> >> implementation is written in pure and "old" C90. Is it for historical
>> >> reasons?
>> >> C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
>> >> suitable to implement an OOL with another one.
>> > One thing that comes to mind is that it's much easier to distribute C
>> > libraries than C++ libraries.
>> In the beginning of C++ there were programs that just converted C++ to C
>> (frontends). At least that is how the C++ compiler Acorn sold worked.
>> So I don't think your argument was much true back then.
> No, it was that way back then too.  They might all generate C code but
> different C code by different backends wouldn't be able to call each
> other natively.

If you convert C++ to C, and compile the C code then that's not
different from compiling the C code itself, correct?

> For instnace the function
> int foo(int);
> might be name-mangled this way in one cfront:
> foo$d
> and this way in another:
> ____int_foo__int_i

But they call both the C libraries in the same way.

> The virtual table of this class:
> class Bar {
>     virtual int foo(int);
>     virtual int bar(int);
> };
> might be generated like this in one cfront:
> struct Bar$$Vtable$ {
>     int (*Bar$$bar$d)(int);
>     int (*Bar$$foo$d)(int);
> };
> and like this in another:
> struct ____class_Foo___vtable_ {
>     int (*foo)(int);
>     int (*bar)(int);
> };
> So, just because they both generated C code, it doesn't mean they can
> call one another.

Why would they need to call each other? The compiled C++ code ends up as
being compiled generated C code.

It has been a while, but I am quite sure that the Acorn C++ front end I
used could dump the actual generated C code. And this generated code
should compile with a normal C compiler on a different platform.

The only exception I can think of is if the front end comes with
libraries you have to link against. But since this should be C as well
(since there is no native C++), I don't see any problem to recreate
those libraries.

John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development

More information about the Python-list mailing list