My GCC 7.3.0 and 8.2.0 has some strange behavior I can't explain. This program, which obviously ends in a Segmentation fault:
int main()
{
double array[2]={0, 0};
printf("%f\n", array[999]);
return 0;
}
This is a long-standing, documented limitation in GCC. Quoting the manual for GCC 3.0<\/a> :
If you don't specify
-O<\/code> , you simply won't get these warnings.
This is because, at some point between GCC 3.0 (released 2001) and GCC 8.2 (released 2018) the compiler was improved so that it will<\/em> give warnings for at least some uses of uninitialized variables when not optimizing. For instance, the trivial test
You can implement a set of rules that are conservatively correct (they will detect all uses of uninitialized variables, but they may claim that some variables are used uninitialized when they aren't), eg Java's definite assignment<\/a> rules, but that approach has historically been unpopular among C programmers. Given a demand for minimal false positives but also quick compilation when not optimizing, GCC's approach of doing more elaborate analysis when optimization is on is understandable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.