What are exact requirements on automatic storage duration?

后端 未结 2 422
北恋
北恋 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条回答
  • 2021-01-04 08:36

    "Lasts until" also is a minimum.

    0 讨论(0)
  • 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...

    0 讨论(0)
提交回复
热议问题