From: Carl Banks on
On Aug 9, 6:39 am, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> candide wrote:
> > Python is an object oriented langage (OOL). The Python main
> > implementation is written in pure and "old" C90. Is it for historical
> > reasons?
>
> The fact that Python is OOP doesn't mean that the implementation of it has
> to be written using an OOP language.
>
> Other than that, I'm actually surprised that nobody mentioned that Python
> actually _is_ written in C++. Yes, it's restricted to a subset thereof that
> is compatible to C, but you could also claim that it was written in a
> subset of C compatible to C++.
>
> :)

I highly doubt the Python source would build with a C++ compiler.

C++ is "'mostly' 'backwards' compatible" with C insofar as you can
pretty easily write C code that is also legal (and semantically
equivalent) C++. But if you don't actively try to write code that is
compatible with both languages, chances are the C code will invoke one
of those "'minor' 'backwards' incompatibilies", the most common one
being failure to cast a pointer.


Carl Banks
From: Christian Heimes on
> I highly doubt the Python source would build with a C++ compiler.
>
> C++ is "'mostly' 'backwards' compatible" with C insofar as you can
> pretty easily write C code that is also legal (and semantically
> equivalent) C++. But if you don't actively try to write code that is
> compatible with both languages, chances are the C code will invoke one
> of those "'minor' 'backwards' incompatibilies", the most common one
> being failure to cast a pointer.

Indeed:

g++ -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3
-Wall -I. -IInclude -I./Include -DPy_BUILD_CORE -o Parser/parsetok.o
Parser/parsetok.c
Parser/parsetok.c: In function 'node* parsetok(tok_state*, grammar*,
int, perrdetail*, int*)':
Parser/parsetok.c:251: error: invalid conversion from 'void*' to 'char*'
make: *** [Parser/parsetok.o] Error 1

Beside from several invalid conversions Python could most probably be
compiled with a g++ compiler. I once worked on a patch to fix the
conversion issues but Martin argued against it. There isn't really a
point in cluttering the source with type casts.

Christian

From: Ulrich Eckhardt on
Carl Banks wrote:
> I highly doubt the Python source would build with a C++ compiler.

As Christian showed, it doesn't. However, look around the sources a bit.
There are lots of places where e.g. the returnvalue of malloc() (or,
rather, the macro that resolves to something like it) is explicitly
type-cast to the according pointer type. When asked on the developers'
list, it was said that this was intended for compatibility with C++, e.g.
in cases where people want to embed Python into their C++ projects. Of
course, this contradicts Christian's statement that C++ compatibility
wasn't considered useful enough.

*shrug*


Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: Lawrence D'Oliveiro on
In message <mailman.1863.1281378450.1673.python-list(a)python.org>, Christian
Heimes wrote:

> There isn't really a point in cluttering the source with type casts.

Makes you wonder why they bothered using a typed language at all.
From: Carl Banks on
On Aug 10, 12:06 am, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote:
> Carl Banks wrote:
> > I highly doubt the Python source would build with a C++ compiler.
>
> As Christian showed, it doesn't. However, look around the sources a bit.
> There are lots of places where e.g. the returnvalue of malloc() (or,
> rather, the macro that resolves to something like it) is explicitly
> type-cast to the according pointer type. When asked on the developers'
> list, it was said that this was intended for compatibility with C++, e.g.
> in cases where people want to embed Python into their C++ projects. Of
> course, this contradicts Christian's statement that C++ compatibility
> wasn't considered useful enough.

I question why it needs to be compatible with C++ to be able to embed
Python in a C++ project. How many C++ compilers out there don't come
bundled with a C compiler?


Carl Banks