There are many statements in C that does nothing. That means that removing them will have no observable change in program behavior.
According to the C standard, Are C compilers allowed to optimize away these redundant statements?
For example, if we have code like this:
#include <stdio.h>
void f(void);
int main(void){
printf("a");
f(); // function call statement that provably does nothing
printf("b");
1000; // redundant expression statement
printf("c");
; // null statement
printf("d");
int x = 1; // assignment statement that is not used
printf("e");
return 0;
}
void f(void){
1000; // redundant expression statement
; // null statement
int x = 1; // assignment statement that is not used
}
Is the compiler allowed to produce the same object code as below? :
#include <stdio.h>
void f(void);
int main(void){
printf("a");
printf("b");
printf("c");
printf("d");
printf("e");
return 0;
}
void f(void){
}