What are exact requirements on automatic storage duration?

后端 未结 2 446
北恋
北恋 2021-01-04 08:19

Depending on the compiler the following code:

int main()
{
   srand( 0 );
   if( rand() ) {
      char buffer[600 * 1024] = {};
      printf( buffer );
   }          


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 08:37

    I read 3.7/ as an introductory description and definition of the different storage classe (automatic, static, dynamic) and not as the implementation requirement for each... the implementation requirement for automatich is then described in 3.7.2/1 .

    Reading 3.7.2/1 it does not forbid that it exists longer than the block exists (that is just the minimum) - IMHO this is an opening for compiler implementors regarding possible optimizations...

提交回复
热议问题