static initialization order fiasco

前端 未结 4 1025
长发绾君心
长发绾君心 2020-11-22 12:20

I was reading about SIOF from a book and it gave an example :

//file1.cpp
extern int y;
int x=y+1;

//file2.cpp
extern int x;
int y=x+1;  
<
4条回答
  •  有刺的猬
    2020-11-22 13:07

    The whole point (and the reason it's called a "fiasco") is that it's impossible to say with any certainty what will happen in a case like this. Essentially, you're asking for something impossible (that two variables each be one greater than the other). Since they can't do that, what they will do is open to some question -- they might produce 0/1, or 1/0, or 1/2, or 2/1, or possibly (best case) just an error message.

提交回复
热议问题