【发布时间】:2012-03-14 20:25:29
【问题描述】:
在长时间的中断之后,我又回到了 c。这是我编写的用于输出文件大小的小程序。它可以编译,并且可以正常工作,并且几乎是从手册页中复制和粘贴的。但这给了我来自 gcc 的恼人警告。
gcc -ggdb read_file_to_char_array.c -o read_file_to_char_array `mysql_config --cflags --libs && pkg-config --cflags --libs gtk+-2.0 && pkg-config --cflags --libs sdl`
read_file_to_char_array.c: In function ‘main’:
read_file_to_char_array.c:22:19: warning: [enabled by default]
/usr/include/i386-linux-gnu/sys/stat.h:216:12: note: expected ‘int’ but argument is of type ‘struct FILE *’`
关于如何让它消失的任何提示(不禁用警告;))
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv) {
unsigned long *lengths;
FILE *fp;
struct stat sb;
fp = fopen("image.png", "rb");
fstat(fp,&sb);
printf(" Size - %lld : ", (long long)sb.st_size);
fclose(fp);
}
【问题讨论】:
-
我在你的程序中只计算了 20 行,所以我看不到警告指的是哪一行 - 介意发布整个内容,也许在 [pastebin](www.pastebin.com) 上?
-
+1 使用“rb”作为图像文件
标签: c pointers casting warnings stat