数组维界基址和数组映象函数常量基址 理解问题 ,谢谢
程序代码:#include<stdarg.h>
#define MAX_ARRAY_DIM 8 //假设数组维数的最大值为8
typedef struct {
ElemType *base; //数组元素基址,由InitArray分配
int dim; //数组维数
int *bounds; //数组维界基址,由InitArray分配
int *constants; //数组映象函数常量基址,由InitArray分配
}Array;
Status InitArray(Array &A,int dim,...){
//若维数dim和随后的各维长度合法,则构造相应的数组A,并返回OK。
if (dim<1 ||dim>MAX_ARRAY_DIM) return ERROR;
A.dim=dim;
A.bounds=(int *)malloc(dim*sizeof(int));
if (!A.bounds) exit(OVERFLOW);
//若各维长度合法,则存入A.bounds,并求出A的元素总数elemtotal。
elemtotal=1;
va_start(ap,dim); //ap为va_list类型,是存放变长参数表信息的数组。
for (i=0;i<dim;++i){
A.bounds[i]=va_arg(ap,int);
if (A.bounds[i]<0) return UNDERFLOW;
elemtotal * = A.bounds[i];
}
va_end(ap);
A.base=(ElemType *)malloc(elemtotal *sizeof(ElemType));
if (!A.base) exit (OVERFLOW):
//求映象函数的常数ci(i为下标),并存入A.constants[i-1],i=1,...dim。
A.constants=(int *)malloc(dim *sizeof(int));
if (!A.constants)exit (OVERFLOW);
A.constants[dim-1]=1;
for (i=dim-2;i>=0;--i)
A.constants[i]=A.bounds[i+1] * A.constants[i+1];
return OK;
}
status Locate(Array A,va_list ap,int &off){
//若ap指示的各下标值合法,则求出该元素在A中相对地址off。
off=0;
for (i=0;i<A.dim;++i){
ind=va_arg(ap,int);
if (ind<0 || ind>=A.bounds[i]) return OVERFLOW;
off + = A.constants[i] * ind;
}
return OK;
请问各位前辈,数组维界基址,即代码中的A.bounds,是用来储存什么的?而A.constants又是用来储存什么的?查询过相关资料,还是不明白。尤其是代码中的A.constants[dim-1]为什么要把1,赋给它?
希望各位前辈帮忙解答一下,谢谢。









