c++builder - How can I find the number of elements of a multidimentional dynamic array -
my pointer declared in header file:
int (*array)[10];
i pass argument function initializes array:
void __fastcall tform1::initarray(const int cnt) { try { form1->array = new int[cnt][53]; } catch(bad_alloc xa) { application->messageboxa("memory allocation error sel. ", mb_ok); } form1->zeroarray(); } //---------------------------------------------------------------------------
i set element of array "0":
void __fastcall tform1::zeroarray() { __int16 cnt = sizeof_array(array); // here notice problem. cnt not correct size of first level of array. if(cnt) { for(int n = 0; n < cnt; n++) { for(int x = 0; x < 53; x++) { form1->array[n][x] = 0; } } } } //---------------------------------------------------------------------------
this defined size of array macro:
#define sizeof_array(a) (sizeof((a))/sizeof((a[0])));
when array created 10 elements of 53 elements array[10][53]
return sizeof_array == 0
. should equal 10.
i have tried several variation of macro , doing straight math sizeof()
cannot correct output. not doing?
Comments
Post a Comment