LINUX.ORG.RU

История изменений

Исправление bormant, (текущая версия) :

При чём тут личные предпочтения?!

Стандарт языка Си говорит нам

6.5.2.1 Array subscripting
Constraints
1 One of the expressions shall have type “pointer to complete object type”, the other expression shall
have integer type, and the result has type “type”.
Semantics
2 A postfix expression followed by an expression in square brackets [] is a subscripted designation of
an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical
to (*((E1)+(E2)))
. Because of the conversion rules that apply to the binary+ operator, if E1 is an
array object (equivalently, a pointer to the initial element of an array object) and E2 is an integer,
E1[E2] designates the E2 -th element of E1 (counting from zero).

E1[E2] is identical to (*((E1)+(E2)))


Идентичны они, так говорит нам стандарт.

Именно поэтому выбор одной (краткой) или другой (длинной) записи является только и исключительно предметом личных предпочтений.

Надеюсь, мне на этот раз удалось донести мысль?


PS. Доводы про упоминание array object тут не работают, ибо а) случай с указателем упомянут явно, б) для арифметики указателей применяются те же самые ограничения, иначе UB ;)

Исходная версия bormant, :

При чём тут личные предпочтения?!

Стандарт языка Си говорит нам

6.5.2.1 Array subscripting
Constraints
1 One of the expressions shall have type “pointer to complete object type”, the other expression shall
have integer type, and the result has type “type”.
Semantics
2 A postfix expression followed by an expression in square brackets [] is a subscripted designation of
an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical
to (*((E1)+(E2)))
. Because of the conversion rules that apply to the binary+ operator, if E1 is an
array object (equivalently, a pointer to the initial element of an array object) and E2 is an integer,
E1[E2] designates the E2 -th element of E1 (counting from zero).

E1[E2] is identical to (*((E1)+(E2)))


Идентичны они, так говорит нам стандарт.

Именно поэтому выбор одной (краткой) или другой (длинной) записи является только и исключительно предметом личных предпочтений.

Надеюсь, мне на этот раз удалось донести мысль?


PS. Доводы про упоминание array object тут не работают, ибо для арифметики указателей применяются те же самые ограничения, иначе UB ;)