6 ms·
There is something personally poetic (is that a thing? it's poetic to me, but maybe not to you?) about a C feature I was unaware of despite working in the langu
by tptacek 8y ago
There is something personally poetic (is that a thing? it's poetic to me, but maybe not to you?) about a C feature I was unaware of despite working in the language for 25 years being yet another way in which the keyword "static" is overloaded.
It's as if they go around looking for places in the grammar they can unambiguously stick "static" and then back-rationalize a meaning for it.
- robertelder 8y agoIf 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.
- bdamm 8y agoHaving written a parser for C I can tell you that parameter type declarations are an absolute bear to parse. Wow.
- derefr 8y ago> It's as if they go around looking for places in the grammar they can unambiguously stick "static" and then back-rationalize a meaning for it. I would think that that's exactly what they do, in order to avoid breaking existing code by introducing any more reserved words.
- coldtea 8y agoIf only they'd thought of using a special prefix for reserved words, e.g. _.
- gaius 8y agoThose are the words that are part of the language itself! The _ prefix is used for variables.
- coldtea 8y agoI know. I mean if they differentiated keywords like static with _ (and didn't allow it as a variable prefix) then they could have an infinite number on non-clashing language keywords...
- int_19h 8y agoThat's exactly how it works for all new (from C99 onward) keywords. The actual keywords are defined with a leading underscore and a capital letter. The standard reserves all such identifiers for implementation, and so no valid conforming program should contain any such. Thus, you get keywords like _Bool and _Complex. And then, to make them look nice, there are headers like <stdbool.h> which basically just do #define bool _Bool etc.
- emmelaich 8y agoThey're trying to avoid introducing new keywords or funky punctuation, both worthy goals.