Lies in education [was Re: The "loop and a half"]

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Oct 12 02:03:13 EDT 2017


bartc wrote:
> The original has an extra pointer so idiomatic C might be more:
> 
>     tokenrec ***

I was going by your English description, which when translated
into C gives only two pointers.

But I think you're right that the C version really has 3 levels
of indirection, so the meaning of "array" in the original
language must be something different from what it is in C.

My point was that C makes very little distinction between
"pointer to foo" and "pointer to first element of array
of foo", so it's not usual practice to write declarations
as convoluted as "* (*)[]".

> If you want to lose all array information, and really don't care if 
> you're dealing with a pointer, or an array (and don't mind changing how 
> such a value is passed, and how it is accessed) then this is fine for you.

You lose that information in C anyway. There's no way for the
function to tell whether it was passed a pointer to a single
value or a pointer to an array, and if the latter, how many
elements are in the array. If you want that information passed,
you have to arrange it separately. You don't get it just by
writing "* (*)[]" instead of "***" for the argument type.

-- 
Greg



More information about the Python-list mailing list