我有一个非常小的 C 程序,可以反转文件。它在 Windows 上编译为exe大小为 28,672 字节的文件。
/O1并且/Os似乎没有任何效果)?顺便说一句 - 当我编译时,gcc我得到大约 50Kb 文件,当我编译时,cl我得到 28Kb。
编辑:这是代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fi, *fo;
char *file1, file2[1024];
long i, length;
int ch;
file1 = argv[1];
file2[0] = 0;
strcat(file2, file1);
strcat(file2, ".out");
fo = fopen(file2,"wb");
if( fo == NULL )
{
perror(file2);
exit(EXIT_FAILURE);
}
fi = fopen(file1,"rb");
if( fi == NULL )
{
fclose(fo);
return 0;
}
fseek(fi, 0L, SEEK_END);
length = ftell(fi);
fseek(fi, 0L, SEEK_SET);
i = 0;
while( ( ch = fgetc(fi) ) != EOF ) {
fseek(fo, length - (++i), SEEK_SET);
fputc(ch,fo);
}
fclose(fi);
fclose(fo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
更新:
/MD生成一个 16Kb 文件。tcc(Tiny C Compiler)编译生成一个 2Kb 文件。gcc -s -O2生成一个 8Kb 文件。