> Looking into Python's sources, I find mostly code like this: > > static PyObject * > func_get_code(PyFunctionObject *op) > { > .... > } > > static PyGetSetDef func_getsetlist[] = { > {"func_code", (getter)func_get_code, (setter)func_set_code}, > .... > {NULL} /* Sentinel */ > }; > > > > in other words, casting like hell to the correct function type. > > Should a style like this should be preferred: > > static PyObject * > func_get_code(PyObject *py) > { > PyFunctionObject *op = (PyFunctionObject *)py; > .... > } > > static PyGetSetDef func_getsetlist[] = { > {"func_code", func_get_code, func_set_code}, > .... > {NULL} /* Sentinel */ > }; > > > in other words, move the cast where you are more sure about it's correctness, > and give the compiler a change for meaningfull warnings. I find that using the first form generally you end up using fewer casts, and that's my preference (because casts obscure the code). This is one area where I wish we could use C++, so e.g. PyFunctionObject would be a subclass of PyObject... :-( --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4