[Pyrex] Re: Re: Pyrex and C++
David J. C. Beach
beach at verinet.com
Wed Nov 19 21:02:00 CET 2003
On Wed, 2003-11-19 at 14:28, Mike Rovner wrote:
> Greg Ewing wrote:
> > Pyrex currently generates code which casts lvalues, e.g.
> >
> > MyExtensionType *p;
> > (PyObject *)p = some_pyobject_expr;
> >
> > which is apparently illegal in C++.
>
> It seems to be legal C++. See ISO 5.4:
> """
> The result of the expression (T) cast expression is of type T. The
> result is an lvalue if T is
> a reference type, otherwise the result is an rvalue.
> """
It would seem to me that this means that the user would be required to
issue:
(PyObject*&) p = some_pyobject_expr;
(casting p to be a reference to a pointer.)
Pointer values are not "references" in the C++ sense of the word.
Remember that C++ has an explicit "reference" type, denoted with an
ampersand (&). This allows you to write functions that have IN/OUT
arguments without using pointers, for example:
void addOneTo(int& x) {
++x;
}
(or better yet...)
template<class T>
void increment(T& t) {
++t;
}
Not that either of these constitutes a particularly useful function...
Dave
--
David J. C. Beach
<beach at verinet.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20031119/71e6476e/attachment.bin
More information about the Pyrex
mailing list