Linux下编程遇到的转换错误,要如何修改?

main.cc:118:43: error: invalid conversion from ‘void*’ to ‘_u32* {aka unsigned int*}’ [-fpermissive]
cache->addr_list = realloc(cache->addr_list, cache->addr_list_size * sizeof(_u32));
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cc: In function ‘void reset_cache_sim(cache_sim*, int, int)’:
main.cc:179:42: error: invalid conversion from ‘void*’ to ‘_u8* {aka unsigned char*}’ [-fpermissive]
cache->cache_buf = malloc(cache->cache_size);
~~~~~~^~~~~~~~~~~~~~~~~~~
main.cc:189:31: error: invalid conversion from ‘void*’ to ‘cache_item*’ [-fpermissive]
cache->caches = malloc(sizeof(struct cache_item) * cache->cache_item_num);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cc: In function ‘void load_trace(cache_sim*, char*)’:
main.cc:361:51: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
do_cache_op(cache, (void*)addr, 1);
^~~~
main.cc:364:51: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
do_cache_op(cache, (void*)addr, 0);
^~~~
main.cc: At global scope:
main.cc:411:55: error: ISO C++ forbids declaration of ‘do_test’ with no type [-fpermissive]
static do_test(struct cache_sim* cache, char* filename)
^
main.cc: In function ‘int main(int, char**)’:
main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
st_cases[] = {"gcc.trace","gzip.trace","mcf.trace","swim.trace","twolf.trace"};
^
main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

错误描述是这样的,求大神解答

1个回答

 找到:main.cc:118行
cache->addr_list = (_u32*)realloc(cache->addr_list, cache->addr_list_size * sizeof(_u32));
加上强制转换,别的类似
qq_43222166
qq_43222166 回复caozhy: 好的,感谢解答
一年多之前 回复
caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复qq_43222166: 这个说的是,你下面的数组是常量,你不能修改。只是警告,如果你不修改,是没事的。这么写:test_users[1][2] = 's'; 是非法的。
一年多之前 回复
qq_43222166
qq_43222166 回复caozhy: gcc.trace那些是测试文件,有这一行代码能解决问题么?
一年多之前 回复
qq_43222166
qq_43222166 回复caozhy: gcc.trace
一年多之前 回复
qq_43222166
qq_43222166 回复caozhy: 不好意思,突然发现没显示完整,main.cc:429:94: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings] char* test_cases[] = {"gcc.trace","gzip.trace","mcf.trace","swim.trace","twolf.trace"};
一年多之前 回复
caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复qq_43222166: 前面的问题之所以我能回答,是因为下面列出了代码,这个没有列出代码,我怎么知道。是不是你试图让字符串指向char *了。
一年多之前 回复
qq_43222166
qq_43222166 回复caozhy: 问题解决了,已采纳,可以的话能告诉一下底下几个warninn要怎么解决么,非常感谢
一年多之前 回复
caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复qq_43222166: static void do_test(struct cache_sim* cache, char* filename),加上返回值类型(或者void)。如果问题解决,麻烦点下我回答右边的采纳。
一年多之前 回复
qq_43222166
qq_43222166 非常感谢,还想问一下,main.cc:411:55: error: ISO C++ forbids declaration of ‘do_test’ with no type [-fpermissive] static do_test(struct cache_sim* cache, char* filename)这条怎么改呢?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问