CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

Misleading statement about built-in array subscripts

Open Keith-S-Thompson opened this issue 3 years ago • 0 comments

ES.107 says:

Note The built-in array uses signed subscripts.

This is misleading. The built-in indexing operator can use either signed or unsigned subscripts.

The C++17 standard, section 8.2.1 [expr.sub] says:

A postfix expression followed by an expression in square brackets is a postfix expression. One of the expressions shall be a glvalue of type “array of T” or a prvalue of type “pointer to T” and the other shall be a prvalue of unscoped enumeration or integral type.

There's no suggestion in the standard that an index should be signed (or that it should be unsigned).

Keith-S-Thompson avatar Apr 20 '22 18:04 Keith-S-Thompson