What does the ISO/IEC 9899 6.8.4.2 ->2 phrase mean? [duplicate]

五迷三道 提交于 2019-12-13 00:00:37

问题


I don't get it what this means. I already thought this could mean code as in my code snippet of this Question:

Skipping switch cases via false loop is a valid operation?

But as the answerers just where going to improve the code and ignored my question about the c99 quote, I'm going to ask this here now explicitly:

If a switch statement has an associated case or default label within the scope of an identifier with a variably modified type, the entire switch statement shall be within the scope of that identifier.135)

And here's the footnote:

135) That is, the declaration either precedes the switch statement, or it follows the last case or default label associated with the switch that is in the block containing the declaration.

could any one be so kindly and explain it to me in other words? Thanks for the effort.


回答1:


First note that this sentence applies only for identifiers of variably modified type, that is a type that has a dynamic array dimension somewhere in its description. For n a variable something like

double a[n];
unsigned (*B)[n][n];

The objects that are associated to this kind of identifier have a special rule for their life time, it only starts at the point of declaration, whereas for other types it starts at entering the scope.

The paragraph that you are citing is to ensure that all the case of the switch statement has the same property according to that life time on such an object. Either the life of the object has already started, before any of the cases, or it only starts after any of the case (or default) labels.

So in essence it just indicates that you shouldn't mix usage of VLA (or similar) and jump statements, because you can't know what the size is to be and where the memory for the array (if any) has to be allocated.



来源:https://stackoverflow.com/questions/18459972/what-does-the-iso-iec-9899-6-8-4-2-2-phrase-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!