4
我跟着一些类似的帖子来修改代码,但是警告仍然生成。警告:格式'%d'期望类型'int',但参数4的类型为'size_t'
$ g++ ncfile.c -o ncfile -g -lnetcdf
ncfile.c: In function ‘int main(int, char**)’:
ncfile.c:363: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:363: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:364: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
ncfile.c:364: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘size_t’
在周围线363和364块:
for(i = 0; i < ndimsp; i++) {
char * temp_name;
size_t temp_len;
temp_name = (char *)malloc(sizeof(char) * 20);
nc_inq_dim(cid, dimids[i], temp_name, &temp_len);
dimlens[i] = temp_len;
if(dimids[i] == unlimdimidp) printf("\t\t%d %s \tlength: %d (UNLIMITED)\n", i, temp_name, temp_len);
else printf("\t\t%d %s \tlength: %d\n", i, temp_name, temp_len);
total_records *= temp_len;
free(temp_name);
}
我应该摆脱警告。它对结果有害吗?
感谢,
迈克尔
你会想'%zu',不'%zd',但是,作为'size_t'是一个无符号类型。 – 2013-04-28 22:16:04
哇完全错过了,谢谢你的回答已经修复。 – Nomad101 2013-04-28 22:23:12
谢谢。我从你那里学到了。 – 2013-04-28 23:11:45