Tag: 编译器 优化

GCC标准优化行为

在这里,我使用-O2优化级别(使用gcc 4.8.4)编译输入程序并测量执行时间: gcc -O2 -c test.c -o obj.o TIMEFORMAT=’%3R’ && time(./obj.o) execution time = 1.825 当我用-O2 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options等级中的GCC manuel中定义的选项列表替换-O2标志时。 html #Oftimize-这样的选项 : gcc -fauto-inc-dec -fcompare-elim -fcprop-registers -fdce -fdefer-pop -fdse -fguess-branch-probability -fif-conversion2 -fif-conversion -fipa-pure-const -fipa-profile -fipa-reference -fmerge-constants -fsplit-wide-types -ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-slsr -ftree-sra -ftree-pta -ftree-ter -funit-at-a-time -fthread-jumps -falign-functions -falign-jumps […]

是否允许编译器回收释放的指针变量?

有人声称 编译器可以自由地将指针变量重用于其他目的之后 realloc 被释放 ,所以你不能保证它具有与之前相同的价值 即 void *p = malloc(42); uintptr_t address = (uintptr_t)p; free(p); // […] stuff unrelated to p or address assert((uintptr_t)p == address); 可能会失败。 C11附件J.2读 使用指向通过调用free或realloc函数释放的空间的指针的值(7.22.3)[ 未定义 ] 但附件当然不是规范性的。 附件L.3(规范性的,但可选的)告诉我们,如果 引用通过调用free或realloc函数释放的空间的指针值(7.22.3)。 结果被允许是关键的未定义行为。 这证实了这一说法,但我希望从标准本身而不是附件中看到适当的引用。