知道
https://godbolt.org/ 之后,又继续做了没用的语句的测试,用了-O3,
我发现所有的编译器对于 unused()里面的 x = atoi( c1 ); 好像都没有优化掉。
另外,我的汇编只限于20年前本科学过,所以基本都看不懂。
只是看了一下.o里面 _atoi (msvc)或者strotol(gcc等)的个数。
///////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
int uninit( char *c1 )
{
int i, j, x, y;
j = atoi( c1 );
for (i = 0; i < j; i ++) {
x ++;
y = y + 1;
}
return x + y;
}
int unused( char *c1, char *c2 )
{
int x, y, z = 4;
x = atoi( c1 );
x = 5;
y = atoi( c2 );
return x + y + z;
}
int main( int argc, char *argv[] )
{
fprintf( stderr, "%d\n", uninit( argv[1] ) );
fprintf( stderr, "%d\n", unused( argv[1], argv[2] ) );
return 0;
}
--
FROM 14.16.130.*