Lies in education [was Re: The "loop and a half"]
bartc
bc at freeuk.com
Wed Oct 11 18:39:24 EDT 2017
On 11/10/2017 23:03, Gregory Ewing wrote:
> bartc wrote:
>
>> tokenrec * (*)[]
> >
>> the original source and that type is written like this:
>>
>> ref [] ref tokenrec
>
> The idiomatic way to write that type in C would be
>
> tokenrec **
The original has an extra pointer so idiomatic C might be more:
tokenrec ***
But this still defines a different type, namely:
pointer to pointer to pointer to tokenrec
not:
pointer to array of pointer to tokenrec
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 just have to access a 'tokenrec ***args' parameter as ***args. Or
**args[i]. Or *args[i][j]. **(args[i]). Or ***args. Or args[i][j][k].
Yes, any combination will work! Only one will be correct.
In the original source, it can only be accessed one way - the correct
way. Using the non-idiomatic 'tokenrec *(*)[]' in C imposes some extra
constraints, but doesn't do the full job. However my complaint was about
the syntax; the type system of C is another subject.
(How I ended up talking about C in this group I don't know. But
yesterday I mentioned Python in the C group, so ...)
--
bartc
More information about the Python-list
mailing list