简体   繁体   中英

What is variably-modified(VM) type in C

I have been reading below text a number of times, but I don't get it though.

In C99 standard, it defines a variably modified type.

It says

A full declarator is a declarator that is not part of another declarator. The end of a full declarator is a sequence point. If, in the nested sequence of declarators in a full declarator, there is a declarator specifying a variable length array type, the type specified by the full declarator is said to be variably modified. Furthermore, any type derived by declarator type derivation from a variably modified type is itself variably modified.

I have understood all parts before 'Furthermore' in text. I don't understand after 'Furthermore'. Could you give me a example?

Also, How “a pointer to VLA type “ is a variably modified type according to above C standard text?

"declarator type derivation" is a somewhat convoluted term from the part of a type that is defined in the declarator rather than the decl specs -- that is, a pointer, array or function type.

So what this "Furthermore" clause is saying is that any "declarator type derivation" layered on top of a VLA is also variably modified.

An example of such a type would be a pointer to a VLA type.

int (*ptr)[n];

here, ptr is a variably modified type, because the target type of the pointer is variably modified.

As a side note, this clause is NOT present in the C99 standard. It is in the C11 standard, so was added in some draft after the C99 standard was published and standardized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM