Trying to use a makro in C

Just trying to use a simple makro which reserves memory for a 2D array and initialize every the whole array with one value, but the gcc throws this error :

2DMakro.c:39:5: error: expected expression
ALLOC_ARRAY2D(array, int, dim1Makro, dim2Makro, initMakro);

#include <stdio.h>
#include <stdlib.h>



#define ALLOC_ARRAY2D(ARRAY,TYPE,DIM1,DIM2,INIT)
(TYPE **ARRAY;
ARRAY = (TYPE**) malloc(DIM1*sizeof(TYPE));
for(int zeile = 0; zeile < DIM1; zeile++) {        
}
for(int a = 0; a < DIM1;a++){
for(int b = 0; b < DIM2; b++){
    ARRAY[a][b] = INIT;
}
}


#define DEL_ARRAY2D(ARRAY,DIM1)
(for int zeile = 0; zeile < DIM1 ; zeile++) {
for(int spalte = 0; spalte < DIM2 ; spalte++){
//Gibt Speicherplatz frei   
free(ARRAY[zeile]);
}
})


int
main(int argc, char *argv[]) {
//Variabeln
char *type,*dim1,*dim2,*init;
char* dim1P, dim2P,initMakroP;
int dim1Makro, dim2Makro, initMakro;

//char zu integer konvertieren
dim1Makro = atoi(argv[1]);
dim2Makro = atoi(argv[2]);
initMakro = atoi(argv[3]);

ALLOC_ARRAY2D(array, double, dim1Makro, dim2Makro, initMakro);
DEL_ARRAY2D(ARRAY, DIM1);
return 0;
}

Well and this is my .c file, any suggestions what I did wrong?
Thanks in advance.


Source: gcc

Leave a Reply