Цитата(Wano @ Jun 14 2009, 00:13)

ЫЫЫЫЫ чего-то не катит
typedef char TypeD[5][5];
char array[5][5];
void func(TypeD * temp){
...
В disassembly видно что забит сдвиг от начала массива не на пять байт ,а на 25. Всё щастье пашет только на диапазоне *temp[0][0]....*temp[0][4]

Естественно.
temp объявлен как указатель на массив char[5][5]
Соответственно
temp[1] - это
следующий такой массив (
temp[1] есть массив char[5][5]),
temp[1][0] - первый его подмассив,
*temp[1][0], рассматриваемый как
*(temp[1][0]) (приоритеты операций в С желательно выучить до начала программирования) - это нулевой элемент данного подмассива.
То, чего Вы хотите, можно достичь двумя способами
Код
typedef char TypeD[5][5];
void func_1(TypeD *temp){
(*temp)[1][0]=5;
}
void func_2(TypeD temp){
temp[1][0]=5;
}
Код
.text
.global func_1
.type func_1, @function
func_1:
/* prologue: frame size=0 */
/* prologue end (size=0) */
ldi r18,lo8(5)
movw r30,r24
std Z+5,r18
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function func_1 size 4 (3) */
.size func_1, .-func_1
.global func_2
.type func_2, @function
func_2:
/* prologue: frame size=0 */
/* prologue end (size=0) */
ldi r18,lo8(5)
movw r30,r24
std Z+5,r18
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function func_2 size 4 (3) */
причём в первом я не вижу никакого смысла.
Ну а как бы я делал это (точнее, как я уже это делал) - я изобразил в предыдущем своём сообщении.
Кстати, С99 позволяет вообще так:
Код
void func( unsigned size_y, unsigned size_x, char array[size_y][size_x] )
{
array[2][1] = 'a';
}
Код
.text
.global func
.type func, @function
func:
/* prologue: frame size=0 */
/* prologue end (size=0) */
movw r30,r22
lsl r30
rol r31
add r30,r20
adc r31,r21
ldi r24,lo8(97)
std Z+1,r24
/* epilogue: frame size=0 */
ret
/* epilogue end (size=1) */
/* function func size 8 (7) */
.size func, .-func
Только, хоть и прошло уже десять лет, не все компиляторы поддерживают все возможности С99.
И ещё вдогонку.
Массивов в языке С... Ну не так, чтобы нету совсем, но и что есть сказать тяжело.
Есть указатели и развитая арифметика с ними. Есть некий "макрос" из квадратных скобок, который облегчает запись этой арифметики. Именно поэтому функции в "можно достичь двумя способами" выше имеют тождественный код и хоть и должны вызывться по разному на уровне исходника
Код
void func_3()
{
func_1( &array);
func_2( array);
}
но код вызова тоже тождественный
Код
.global func_3
.type func_3, @function
func_3:
/* prologue: frame size=0 */
push r16
push r17
/* prologue end (size=2) */
ldi r16,lo8(array)
ldi r17,hi8(array)
movw r24,r16
rcall func_1
movw r24,r16
rcall func_2
/* epilogue: frame size=0 */
pop r17
pop r16
ret
/* epilogue end (size=3) */
/* function func_3 size 11 (6) */
.size func_3, .-func_3
Более того (специально сделал элемент массива двухбайтовым, чтобі біло чётко видно, что множится на два всегда "истинный" индекс, даже если он стоит перед скобками):
Код
unsigned a[5];
unsigned func_1(unsigned char i)
{
return a[i];
}
unsigned func_2(unsigned char i)
{
return i[a];
}
Код
.global func_1
.type func_1, @function
func_1:
mov r30,r24
ldi r31,lo8(0)
lsl r30
rol r31
subi r30,lo8(-(a))
sbci r31,hi8(-(a))
ld r24,Z
ldd r25,Z+1
ret
.global func_2
.type func_2, @function
func_2:
mov r30,r24
ldi r31,lo8(0)
lsl r30
rol r31
subi r30,lo8(-(a))
sbci r31,hi8(-(a))
ld r24,Z
ldd r25,Z+1
ret
в полном соответствии со стандартом (цитата из C89, в C99 аналогично)
Обратите внимание - "одно из выражений ... другое ..." а не "первое выражение ... второе ...".
Цитата
3.3.2.1 Array subscripting
Constraints
One of the expressions shall have type ``pointer to object type ,'' the other expression shall have integral type, and the result has type `` type .''
Semantics
A postfix expression followed by an expression in square brackets [] is a subscripted designation of a member 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 member of an array object) and E2 is an integer, E1[E2] designates the E2 -th member of E1 (counting from zero).
Ну а если E1 - интегральный тип а E2 массив (или, что эквивалентно, указатель на его первый элемент), то тогда это будет E1-тый элемент массива E2.
Так что берите на вооружение
это и не ограничивайте себя тем, что все массивы должны иметь одинаковую длину. Всё равно в функцию реально передаётся указатель на первый элемент массива - даже когда Вы думаете, что передаёте массив.
А вот ещё из стандарта С++, чтобы окончательно
запутать развеять сомнения.
Цитата
When several ”array of” specifications are adjacent, a multidimensional array is created; the constant expressions that specify the bounds of the arrays can be omitted only for the first member of the sequence. [Note: this elision is useful for function parameters of array types, and when the array is external and the definition, which allocates storage, is given elsewhere. ] The first constant-expression can also be omitted when the declarator is followed by an initializer (8.5). In this case the bound is calculated from the number of initial elements (say, N) supplied (8.5.1), and the type of the identifier of D is ”array of N T.”
Except where it has been declared for a class (13.5.5), the subscript operator [] is interpreted in such a way that E1[E2] is identical to *((E1)+(E2)). Because of the conversion rules that apply to +, if E1 is an array and E2 an integer, then E1[E2] refers to the E2-th member of E1. Therefore, despite its asymmetric appearance, subscripting is a commutative operation.
p.s. выделения везде мои