Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Is 'everything' a refrence or isn't it?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Duncan Booth, post: 1857302"] No, Python itself only allocates one integer object holding the value 2, but that isn't necessarily the only object which can compare equal to 2, nor even the only integer object with the value of 2 (a C extension could create another). I seem to remember that at one time Python tried to 'optimise' the comparison by saying that if the addresses are equal the objects are equal, and if the addresses are not equal call the __eq__ method, but this doesn't work in general as it is possible for an object to not be equal to itself. (e.g. a NaN or a user defined class). A suitable short equivalent for the comparison is: if (*i == *(&_i2)) ... but a closer equivalent of what Python really does might be: object *_tmp = &_i2; if ((PyInt_CheckExact(i) && PyInt_CheckExact(_tmp)) ? *i==*_tmp : PyObject_RichCompare(i, _tmp, PyCmp_EQ)) ... i.e. check the types (not that you could actually do that with the C translation of the code) for two integers which fit in the range of C longs and compare the values if possible, otherwise call some horrendously complex comparison code. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Is 'everything' a refrence or isn't it?
Top