Why not allow empty code blocks?

BartC bc at freeuk.com
Mon Jul 25 05:44:53 EDT 2016


On 25/07/2016 02:04, Gregory Ewing wrote:
> BartC wrote:
>> (They don't need to be elaborate to start being confusing. Take 'int
>> *a[]' and 'int (*a)[]'; one of these is an array of pointers, the
>> other a pointer to an array. Quite different! But which is which?
>
> Where have you seen 'int (*a)[]' used? I don't think I've
> ever seen any real-life C code that used a pointer to an
> array, as opposed to a pointer to the first element of the
> array.

(Yes everyone uses T*a (pointer to T) instead of T(*a)[] (pointer to 
array of T), because, thanks to how C mixes up deferencing and indexing, 
the former can be accessed as a[i] instead of (*a)[i].

But it's wrong, and leads to errors that the language can't detect. Such 
as when a points to a single element not a block: define ANY combination 
such as 'pointer to pointer to array'; you need to access an element 
using (deref, deref, index), but C also allows (index, deref, deref) or 
(deref, index, deref), or (index, index, index).

Provided the right number of deref/index ops are provided, C can't tell 
the difference because derefs and index ops are interchangeable! But 
only one combination is correct.

I came across T(*a)[] when translating from a language that handles this 
properly, into C. In fact I use the translator to convert type-specs 
from straightforward format into C. Another tool to get around a flaw.)

-- 
Bartc



More information about the Python-list mailing list