> For this purpose, it would be good if GCC had a type, say, __gcc_index_t, > that -fsanitize=undefined will make produce a diagnostic is a value < 0 > or > PTRDIFF_MAX is assigned.
Actually, this is a special case of a range type. If we could have Ada's range types [1] in C, with overflow check enabled by -ftrapv or -fsanitize=undefined, that would be a *great* improvement. Especially as many GNU packages use C as an application programming language rather than as a system programming language. Bruno [1] https://en.wikibooks.org/wiki/Ada_Programming/Types/range