Sujet : Re: C23 thoughts and opinions
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 05. Jun 2024, 08:14:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3p38t$s5n4$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Pan/0.158 (Avdiivka; )
On Tue, 4 Jun 2024 12:48:31 -0500, BGB wrote:
Though, I do have some questionable experimental features, like a
compiler option to cause arrays and pointers to be bounds-checked, which
is sometimes useful in debugging (but in some cases can add bugs of its
own; also makes the binaries bigger and negatively effects performance,
...).
I remember some research being done into this, back in the days of Pascal.
Remember that, in Pascal (and Ada), subranges exist as types in their own
right, not just as bounds of arrays. And this allows the compiler to
optimize array-bounds checks, and sometimes get rid of them altogether.
E.g.
type
boundstype = 1 .. 10;
var
myarr : array [boundstype] of elttype;
index : boundstype;
With these definitions, an expression like
myarr[index]
doesn’t require any bounds-checking. Of course, assignments to index may
require bounds-checking, depending on the types of values involved.