Posts

Showing posts with the label variable-length-array

What does “[*]” (star modifier) mean in C? [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP What does “[*]” (star modifier) mean in C? [duplicate] This question already has an answer here: While trying to implement a C11 parser (for educational purposes), I found that in C11 (p. 470) but also in C99 (p. 412) (thanks Johannes!), the direct declarator is defined as: (6.7.6) direct-declarator: direct-declarator [ type-qualifier-list? * ] At first, I thought this was an error in the grammar (the type list shouldn't be optional). However, when I tried this out in my reference compiler (clang), I got an rather unexpected error: int array[*] = { 1, 2, 3 }; // error: star modifier used outside of function prototype So apparently, (in clang) this is called the star modifier . I quickly learned that they can only be used in function signatures: void foobar(int array[*]) However, they can only be used in the declaration. Trying to use it in a function definition results in an error as well: void foobar(int array[*]) { // variable length array...