4 ms·
If you like that, there is yet another seldom seen feature of c99, the use of '' in an array declarator: echo 'int my_func(int i, int arr[*]);' > main.c
by robertelder 8y ago
If you like that, there is yet another seldom seen feature of c99, the use of '' in an array declarator:
echo 'int my_func(int i, int arr[*]);' > main.c
gcc -c -std=c99 main.c
-- * observe that there are no errors * --
See 6.7.5.2 Array declarators for details
http://port70.net/~nsz/c/c99/n1256.html http://port70.net/~nsz/c/c99/n1256.html
Edit: I can't figure out how to escapse an asterisk, so the above might not read correctly but I tried.
- BeeOnRope 8y agoIf the character following a * is whitespace it will show up as an asterisk without implication of special formatting. In code blocks *asterisks* don't need any special escaping as they always show up "as is".
- shaklee3 8y agoWhat's the point of this? It seems like it's the same as not including the asterisk in the first place.
- xelxebar 8y agoIt seems this only really matters in function prototype declarations that contain multidimensional arrays. Compare: int foo(char [][*]); int bar(char [][]); The second declaration should give an error. I'm getting this from just reading the spec now, but it looks like the reason has to do with "incomplete" versus "complete" types. Something like 'int arr[]' is an "incomplete type", i.e. an array of ints with unspecified size. While 'int arr[*]' is a complete type for an array with variable length. I'm guessing that array elements must have a complete type, which is why the above snippet gives an error.
- anilakar 8y agoIf I understood correctly, this will be removed in C2x.
- CodeArtisan 8y agoThe size of any upper dimension must be known for the array subscribing operator to work, using * allows you to bypass that in function prototypes.