10 years, 9 months ago.

compiler problems

I have written a test program for compiling my matrix function and i have to glow an led if the the function works perfect, but i get an error saying expression must have a constant value , could any one please suggest me how to over come this problem

include the mbed library with this snippet

#include "mbed.h"

int size_b_row1;
int size_b_col1;
int a, b, c, d;
DigitalOut myled(LED1);
void transpose(double matrix[size_b_row1][size_b_col1], double matrix_t[size_b_col1][size_b_row1]);
int isMatrixEqual(double matrix1[a][b], double matrix2[c][d]);
void transpose(double matrix[size_b_row1][size_b_col1], double matrix_t[size_b_col1][size_b_row1])
{
    int i,j;
    for(i=0;i<size_b_row1;i++)
    {
        for(j=0; j<size_b_col1;j++)
            matrix_t[j][i] = matrix[i][j];
    }
}


int isMatrixEqual(double matrix1[a][b], double matrix2[c][d])
{
    int isequal = 1;

    if((a!=c) || (b!=d))
        isequal = 0;
    else
    {
        int i, j;
        for( i=0;i<a;i++)
        {
            for( j=0;j<b;j++)
//              if(matrix1[i][j]!=matrix2[i][j])
                if( abs( (matrix1[i][j]-matrix2[i][j])/matrix1[i][j] )>0.001 )
                {
//                  double gross = abs( (matrix1[i][j]-matrix2[i][j])/matrix1[i][j] );
                    isequal = 0;
                    break;
                }
            if(isequal == 0)
                break;
        }
    }
    return isequal;
}


int main(void) 
{

double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
double TC[4][4];
double C_t[4][4] = {{1,7,1,2},{ 3,6,2,3},{5,2,7,5},{2,2,3,3}};

int Pass = 1;

    size_b_row1 = 4;
    size_b_col1 = 4;
    transpose(C, TC);
    
    Pass = isMatrixEqual(TC, C_t);
    if(Pass == 1)
        myled = 1;

    }

1 Answer

10 years, 9 months ago.

Hi,

C++ standard does not allow to non-constant size of array.

http://stackoverflow.com/questions/9219712/c-array-expresssion-must-have-a-constant-value

Accepted Answer

heyy,Thank you so much !!

posted by RAVI RAJ 24 Jul 2013