我按照一些类似的帖子来修改代码,但是仍然会生成警告。
$ 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);
}
我应该如何摆脱警告。对结果有害吗?
谢谢,
迈克尔