[C++-SIG] Python calling C++ issues
skaller
skaller at maxtal.com.au
Wed Dec 1 16:21:40 CET 1999
David Beazley wrote:
>
> > There's no guarantee of most types in C++, only that a long is at least
> > 1 byte.
>
> >From K & R, 2nd ed., 2:2, verse 8, p. 36:
>
> "Each compiler is free to choose appropriate sizes for its own
> hardware, subject only to the restriction that shorts and ints are at
> least 16 bits, longs are at least 32 bits, and short is no longer than
> int, which is no longer than long."
Those limits do NOT apply to C++: there is NO requirement on the
number of bits, except that it be documented by the vendor.
[The comparative length requirements apply]
The conversion of pointers to ints is not supported in C++:
more precisely, the cast MAY be implemented by the vendor,
if so, the vendor must document it, and it MUST hold
the whole pointer so that:
(void*)(long)(void*) p == p
For those using C Python sources with C++, there are two
gotchas.
1) Enumerations are NOT integers in C++
[Luckily, Guido doesn't use them much]
2) The very core of Python contains a serious
breach of C++ rules: it casts functions
pointers, which is NOT allowed AT ALL.
[I'm responsible for that rule!]
Luckily, this actually works on most C++ compilers.
To Guido's credit, it is the only breach of strict
ISO C++ Standards compliance I'm aware of.
[In fact, there is a way around it .. but Guido has
chosen not to use that technique]
If I can give a summary: the Python core language source
code is in EXCELLENT shape as a C++ program.
--
John Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850
More information about the Cplusplus-sig
mailing list