Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "typedef" a matrix in C

Tags:

c

when defining new data types in C, one can do

    typedef double BYTE;

so later it is possible to do

BYTE length;

etc

I would like to do something like

typedef double[30][30][10] mymatrix;

so later I do

mymatrix AA[10];

so I have 10 matrices of type mymatrix, and I can access them through AA[0], AA[1], etc

Anyway doing this with the GNU C compiler I get errors like

error: expected unqualified-id before '[' token

What am I doing wrong or how could I achieve my objective?

Thanks

like image 763
Open the way Avatar asked Jan 22 '23 16:01

Open the way


2 Answers

The simple answer is define an object named & declared as you want, then stick typedef in front:

double mymatrix[30][30][10] ; // defines a 3-d array.


typdef double mymatrix[30][30][10] ; // defines a 3-d array type

mymatrix  matrix;
like image 129
James Curran Avatar answered Feb 01 '23 12:02

James Curran


Follow "declaration looks like use" C idea:

typedef double mymatrix[30][30][10];
like image 40
Nikolai Fetissov Avatar answered Feb 01 '23 11:02

Nikolai Fetissov