Size: a a a

2021 March 14

O

Ofee in pro.cxx
magras
Да, стандарт гарантирует, что подмассивы будут лежать последовательно. Но из этого не следует что магически меняется размер подмассива.

https://eel.is/c++draft/dcl.array#9
Возможно, это тот случай, когда стоит перестатать гадать над формулировками стандарта и попробовать судить с позиции здравого смысла и исторически накопленного опыта их использования
источник

m

magras in pro.cxx
Ofee
Возможно, это тот случай, когда стоит перестатать гадать над формулировками стандарта и попробовать судить с позиции здравого смысла и исторически накопленного опыта их использования
Ну мой опыт как раз говорит о том, что пользоваться многомерными массивами не удобно и не нужно.
источник

m

magras in pro.cxx
Sergey Skvortsov
А где гарантии?
Then i is added, which on typical implementations ...
Гарантии чуть выше: https://eel.is/c++draft/dcl.array#6
источник

SS

Sergey Skvortsov in pro.cxx
magras
Гарантии чуть выше: https://eel.is/c++draft/dcl.array#6
Ну это же не дает возможности использовать арифметику с указателями, будто перед нами одномерный массив
источник

SS

Sergey Skvortsov in pro.cxx
Строго противоречит http://eel.is/c++draft/expr.add#4
источник

m

magras in pro.cxx
Sergey Skvortsov
Ну это же не дает возможности использовать арифметику с указателями, будто перед нами одномерный массив
Да, с этим я и не спорю. Собственно я на это же указывал выше.
источник

SK

Stas Koynov in pro.cxx
Sergey Skvortsov
Ссылочку бы, совершенно неочевидное свойство
7.2 Array-to-pointer conversion [conv.array]
1 An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to a prvalue of
type “pointer to T”. The temporary materialization conversion (7.4) is applied. The result is a pointer to the
first element of the array.

11.3.4 Arrays
7
[ Note: A consistent rule is followed for multidimensional arrays. If E is an n-dimensional array of rank
i × j × · · · × k, then E appearing in an expression that is subject to the array-to-pointer conversion (7.2)
is converted to a pointer to an (n − 1)-dimensional array with rank j × · · · × k. If the * operator, either
explicitly or implicitly as a result of subscripting, is applied to this pointer, the result is the pointed-to
(n − 1)-dimensional array, which itself is immediately converted into a pointer. [ Example: Consider
int x[3][5];
Here x is a 3 × 5 array of integers. When x appears in an expression, it is converted to a pointer to (the first
of three) five-membered arrays of integers. In the expression x[i] which is equivalent to *(x+i), x is first
converted to a pointer as described; then x+i is converted to the type of x, which involves multiplying i by
the length of the object to which the pointer points, namely five integer objects. The results are added and
indirection applied to yield an array (of five integers), which in turn is converted to a pointer to the first of
the integers. If there is another subscript the same argument applies again; this time the result is an integer.
— end example ] — end note ]
С++17 2017-03-21 Revises: N4640
источник

SS

Sergey Skvortsov in pro.cxx
Stas Koynov
7.2 Array-to-pointer conversion [conv.array]
1 An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to a prvalue of
type “pointer to T”. The temporary materialization conversion (7.4) is applied. The result is a pointer to the
first element of the array.

11.3.4 Arrays
7
[ Note: A consistent rule is followed for multidimensional arrays. If E is an n-dimensional array of rank
i × j × · · · × k, then E appearing in an expression that is subject to the array-to-pointer conversion (7.2)
is converted to a pointer to an (n − 1)-dimensional array with rank j × · · · × k. If the * operator, either
explicitly or implicitly as a result of subscripting, is applied to this pointer, the result is the pointed-to
(n − 1)-dimensional array, which itself is immediately converted into a pointer. [ Example: Consider
int x[3][5];
Here x is a 3 × 5 array of integers. When x appears in an expression, it is converted to a pointer to (the first
of three) five-membered arrays of integers. In the expression x[i] which is equivalent to *(x+i), x is first
converted to a pointer as described; then x+i is converted to the type of x, which involves multiplying i by
the length of the object to which the pointer points, namely five integer objects. The results are added and
indirection applied to yield an array (of five integers), which in turn is converted to a pointer to the first of
the integers. If there is another subscript the same argument applies again; this time the result is an integer.
— end example ] — end note ]
С++17 2017-03-21 Revises: N4640
Это уже кидали и это никак не относится к reinterpret_cast к одномерному массиву
источник

SS

Sergey Skvortsov in pro.cxx
Например, ubsan должен ругаться на такой доступ; кажется, этого достаточно, чтоб не использовать подобную конструкцию
источник

SK

Stas Koynov in pro.cxx
Sergey Skvortsov
Это уже кидали и это никак не относится к reinterpret_cast к одномерному массиву
тоесть вы утверждаете, что массив [3][5] я не могу обработать как массив [15]?
источник

SS

Sergey Skvortsov in pro.cxx
Ну да
источник

SK

Stas Koynov in pro.cxx
:)
источник

SS

Sergey Skvortsov in pro.cxx
Вы слишком хорошо к плюсам относитесь
источник

SK

Stas Koynov in pro.cxx
чувак это просто кусок памяти все! там нет внутри размерностей или типа того, как в делфи. просто память как ты с ней будешь работать это твое дело. посмотри любой код работы с картинками. там когда идет преобразование то это тупо пиксели один за другим. когда работа с обьектами то это двухмерные массивы. это просто удобно. если ты хочешь работать с указателем и каждый раз смещать его через sizeof(размер_пикселя*ширину_картинки) да ради бога...
источник

IZ

Ilia Zviagin in pro.cxx
magras
Да, так можно, пока ты работаешь только с первым столбцом. Как только ты выходишь за него это UB по моим представлениям, так как это массив размера N, а не N*M.
У тебя неверные предоставления
источник

IZ

Ilia Zviagin in pro.cxx
Sergey Skvortsov
Ну это же не дает возможности использовать арифметику с указателями, будто перед нами одномерный массив
Даёт.
источник

SS

Sergey Skvortsov in pro.cxx
Ilia Zviagin
Даёт.
В таком случае это противоречит
http://eel.is/c++draft/expr.add#4
источник

IZ

Ilia Zviagin in pro.cxx
Ну нет
источник

SS

Sergey Skvortsov in pro.cxx
Достойная аргументация
источник

IZ

Ilia Zviagin in pro.cxx
Sergey Skvortsov
В таком случае это противоречит
http://eel.is/c++draft/expr.add#4
Не противоречит
источник