返回一个二维结构,这是我如何声明这个结构我怎样才能解决这个当我尝试从功能
typedef struct cache{
int vaild;
char* tag;
char* data;
}cache;
这是我的主要的一部分调用此函数
struct cache **cacheA = createCache(Setnum,(int)pow(2,blocksize),cachesize);
struct cache **cacheB = createCache(Setnum,(int)pow(2,blocksize),cachesize);
现在这是我所谓的功能
struct cache ** createCache(int numset, int blocksize, int cachesize){
int numcache = (int)((cachesize/blocksize)*numset);
struct cache out[numset][numcache];
int i,j;
for (i=0; i < numset; i++){
for (j=0; j < numcache; j++){
out[i][j].tag = "0";
out[i][j].vaild = 0;
out[i][j].data ="0";
}
}
return out;
}
,当我尝试编译此,它告诉我,
return from incompatible pointer type
function returns address of local variable
(指向行“返回了;”)
我不知道什么是错我的代码,我的意思是函数返回的类型是一样的,我怎么declear“走出去” ,那么是什么原因导致这个问题?
'out'是本地的'createChache'的范围,如果返回一个指向它,指针会叼着它返回'out'将有一刻被摧毁。 –
另一个提到的问题是struct cache **与struct cache cache [numset] [numcache]不是同一类型的对象;' –