0

I am currently reading the Python 2.7 source code and got stuck with the following piece of code, in tupleobject.h:

PyObject *ob_item[1];

and in tupleobject.c (PyTuple_SetItem):

p = ((PyTupleObject *)op)->ob_item + i;

How can we shift pointer by i if ob_item is an array of one PyObject?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
DuXeN0N
  • 1,577
  • 1
  • 14
  • 29

1 Answers1

1

It's how arrays and pointers can be used interchangeable. So it's equivalent to

p = &((PyTupleObject *)op)->ob_item[i];

Is an array name a pointer? goes a little more into detail.

Community
  • 1
  • 1
tynn
  • 38,113
  • 8
  • 108
  • 143