1

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.

Community
  • 1
  • 1
dhein
  • 6,431
  • 4
  • 42
  • 74
  • @SanderDeDycker: the other is rather a dup of this to be honest... – dhein Sep 09 '19 at 06:25
  • Ref. comments in the other question - it was suggested to do it the other way around since the answers there seem a bit more in-depth. – Sander De Dycker Sep 09 '19 at 06:28
  • @dhein If you wish to discuss it, I suggest we open a thread on meta. Generally, we should only care about technical quality when voting and close-voting. This question getting closed won't affect anyone's rep, since it is up-voted and accepted. – Lundin Sep 09 '19 at 07:37

1 Answers1

4

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.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • so "variably modified type" doesn't mean a non const variable, it means a on compile time not known memory size, doesn't it? – dhein Aug 27 '13 at 08:30
  • @Zaibis, in essence yes. Such a compile unknown memory size, or a pointer to such a beast. The problem is twofold, it is not only the memory for the object that must be allocated somewhere, there is also some sort of hidden state (the value that would be returned by `sizeof`) that has to be initialized. – Jens Gustedt Aug 27 '13 at 08:57