ggc 给了我这个错误,我无法相信这个错误是正确的,因为输入和预期参数都是 [8][8] 指向数组的指针,知道这里有什么问题!
main.c: In function ‘main’:main.c:24:3: warning: passing argument 1 of ‘DRESC_Transform’ from incompatible pointer type [enabled by default]
In file included from main.c:1:0:
global.h:13:6: note: expected ‘short int * (*)[8]’ but argument is of type ‘short int (*)[8][8]’
这是 global.h
#include <math.h>
#include <stdio.h>
# define ROW 8
# define COL 8
# define SHIFT_AMOUNT 16
# define SHIFT_MASKT ( 1<<SHIFT_AMOUNT )-1
void DRESC_Transform( short *matrix [ROW][COL]);
void DRESC_Transform( short *matrix [ROW][COL]){
int _tmp_matrix [ROW*COL]; // 2KB REGISTER
for ( unsigned i = 0; i <ROW; i++){
int _tmp0, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7;
_tmp0 = *matrix [i][0];
_tmp1 = *matrix [i][1];
_tmp2 = *matrix [i][2];
_tmp3 = *matrix [i][3];
_tmp4 = *matrix [i][4];
_tmp5 = *matrix [i][5];
_tmp6 = *matrix [i][6];
_tmp7 = *matrix [i][7];
_tmp_matrix [ (i<<3)] = _tmp0 <<SHIFT_AMOUNT;
_tmp_matrix [1 + (i<<3)] = _tmp1 <<SHIFT_AMOUNT;
_tmp_matrix [2 + (i<<3)] = _tmp2 <<SHIFT_AMOUNT;
_tmp_matrix [3 + (i<<3)] = _tmp3 <<SHIFT_AMOUNT;
_tmp_matrix [4 + (i<<3)] = _tmp4 <<SHIFT_AMOUNT;
_tmp_matrix [5 + (i<<3)] = _tmp5 <<SHIFT_AMOUNT;
_tmp_matrix [6 + (i<<3)] = _tmp6 <<SHIFT_AMOUNT;
_tmp_matrix [7 + (i<<3)] = _tmp7 <<SHIFT_AMOUNT;
}
for ( unsigned i = 0; i < ROW; i++){ // a row calculation
int _tmp;
_tmp_matrix[ (i<<3)] = ( _tmp_matrix[ (i<<3)] + _tmp_matrix[1 + (i<<3)] ) >>1;
_tmp = ( _tmp_matrix[ (i<<3)] - _tmp_matrix[1 + (i<<3)] );
_tmp_matrix[1 + (i<<3)] = ( _tmp_matrix[2 + (i<<3)] + _tmp_matrix[3 + (i<<3)] ) >>1;
_tmp_matrix[2 + (i<<3)] = ( _tmp_matrix[4 + (i<<3)] + _tmp_matrix[5 + (i<<3)] ) >>1;
_tmp_matrix[4 + (i<<3)] = _tmp;
_tmp = ( _tmp_matrix[6 + (i<<3)] + _tmp_matrix[7 + (i<<3)] ) >>1;
_tmp_matrix[6 + (i<<3)] = ( _tmp_matrix[2 + (i<<3)] - _tmp_matrix[5 + (i<<3)] );
_tmp_matrix[5 + (i<<3)] = ( _tmp_matrix[1 + (i<<3)] - _tmp_matrix[3 + (i<<3)] );
_tmp_matrix[3 + (i<<3)] = _tmp;
_tmp_matrix[7 + (i<<3)] = ( _tmp_matrix[3 + (i<<3)] - _tmp_matrix[7 + (i<<3)] );
}
for ( unsigned i = 0; i <ROW; i++){
int _tmp0, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7;
_tmp0 = _tmp_matrix [ (i<<3)] >>SHIFT_AMOUNT;
_tmp1 = _tmp_matrix [1 + (i<<3)] >>SHIFT_AMOUNT;
_tmp2 = _tmp_matrix [2 + (i<<3)] >>SHIFT_AMOUNT;
_tmp3 = _tmp_matrix [3 + (i<<3)] >>SHIFT_AMOUNT;
_tmp4 = _tmp_matrix [4 + (i<<3)] >>SHIFT_AMOUNT;
_tmp5 = _tmp_matrix [5 + (i<<3)] >>SHIFT_AMOUNT;
_tmp6 = _tmp_matrix [6 + (i<<3)] >>SHIFT_AMOUNT;
_tmp7 = _tmp_matrix [7 + (i<<3)] >>SHIFT_AMOUNT;
*matrix [i][0] = _tmp0;
*matrix [i][1] = _tmp1;
*matrix [i][2] = _tmp2;
*matrix [i][3] = _tmp3;
*matrix [i][4] = _tmp4;
*matrix [i][5] = _tmp5;
*matrix [i][6] = _tmp6;
*matrix [i][7] = _tmp7;
}
}
这是主要的:
#include "global.h"
void main (){
short matrix [ROW][COL] = {{7, 1, 6, 6, 3, -5, 4, 2}, // <<<<---
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2},
{7, 1, 6, 6, 3, -5, 4, 2}};
DRESC_Transform(&matrix); // <<<---
printf("the transformed matrix is \n");
printf("{");
for ( unsigned i; i <ROW; i++){
for ( unsigned j = 0; j <COL; j++){
printf( "%d,", matrix[i][j]);
}
printf("\b}, \n");
}
printf("\b} \n");
}