I have a very small C program which reverses a file. It compiles on windows to an exe
file of size 28,672 bytes.
/O1
and /Os
doesn't seem to make any effect)?BTW - when compiled with gcc
I get around 50Kb file and when compiled with cl
I get 28Kb.
EDIT: Here is the code
#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;
}
UPDATE:
/MD
produced a 16Kb file.tcc
(Tiny C Compiler) produced a 2Kb file.gcc -s -O2
produced a 8Kb file.Try to compile it using tcc: http://bellard.org/tcc/ .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With