- 论坛徽章:
- 19
|
回复 6# timothyqiu
额,我也是在论坛上看到的UB,以前可能见过,没注意过
刚刚测试了一下,编译器确实有这种警告,有警告的话,就没有多少关系了- int main(int argc, char *argv[])
- {
- int a = 5;
- a += a -= a * a;
- printf("%d", a);
- return 0;
- }
复制代码 下面是Eclipse+MinGW的构建结果- 22:24:45 **** Rebuild of configuration Debug for project file_2.2.3 ****
- Info: Internal Builder is used for build
- gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "bin\\file_2.2.3.o" "..\\bin\\file_2.2.3.c"
- ..\bin\file_2.2.3.c: In function 'main':
- ..\bin\file_2.2.3.c:42:4: warning: operation on 'a' may be undefined [-Wsequence-point]
- ..\bin\file_2.2.3.c:42:4: warning: operation on 'a' may be undefined [-Wsequence-point]
- gcc -o file_2.2.3.exe "bin\\file_2.2.3.o"
- 22:24:46 Build Finished (took 1s.575ms)
复制代码 |
|