On 26/07/2016 08:21, Gregory Ewing wrote:
BartC wrote:
(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:
This is an implementation issue, not a language issue.
A sufficiently pedantic implementation could and would
detect this kind of error at run time. Most implementations
of C are not that pedantic, but you can't blame the
language for that.
(No, it's a language issue. Yes you might be able to have a sufficiently
complex (and slow) implementation that at best could detect errors at
runtime, but that's not much help.
It boils down to this: if you have a pointer type T*, does it point to a
standalone T object, or to an array or block of T objects?
The language allows a pointer P of type T* pointing to a single T object
to be accessed as P[i]. Apparently this is not seen as a problem...
(More observations about C here:
https://github.com/bartg/langs/blob/master/C%20Problems.md))
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list