3 ms·
In practice, the [static n] notation can give you useful warnings and bounds checking. https://godbolt.org/z/PzcjW4zKK https://godbolt.org/z/PzcjW4zKK And whi
by uecker 5mo ago
In practice, the [static n] notation can give you useful warnings and bounds checking.
https://godbolt.org/z/PzcjW4zKK https://godbolt.org/z/PzcjW4zKK
And while the (*array_ptr)[3] notation take a moment to get used to, it is very logical. If you have a pointer to an array, you dereference it first and then indx into it. Again, useful for bounds checking: https://godbolt.org/z/ao1so9KP7 https://godbolt.org/z/ao1so9KP7
- dnautics 5mo agoWhat is **int[3][5]
- ori_b 5mo agoA syntax error. You need a variable name, not a type name, in the middle.
- thrance 5mo agoA pointer to a pointer to a pointer to a pointer of integers.
- kazinator 5mo agoIn C declaration syntax, there is a "stem" called declaration specifiers consisting of specifiers and qualifiers. That's where int can appear. After that, there is a declarator. In some cases, multiple declarators separated by a comma, which share the same "stem". int a, b, *c; // one stem consisting of "int", three declarators. The * is declarator syntax for deriving a pointer type. It never appears such that a type specifier would come after it somewhere to the right. Some languages have extended the C declaration syntax such that the type derivators can be moved from the declarator part to the "stem". For instance, as an alternative to: int a[10]; you can write int[10] a; This is how we could get **int[3] as a declarator stem indicating an array of 3 pointers to pointers to int. But it's not in C.
- arcfour 5mo agoThe work of the mythical four star programmer? https://wiki.c2.com/?ThreeStarProgrammer https://wiki.c2.com/?ThreeStarProgrammer
- keyle 5mo agoI know of this notations but I don't see many people using [static n]. Not sure why, maybe it doesn't feel like C anymore, maybe it feels hacky? typically if you're passed an array you'd want to get more anyway, so you'd get passed a struct. Not sure.
- uecker 5mo agoI don't know. I see people increasingly make use of it. The problem was that in the past compilers ignored this completely, so there was simply no point. Nowadays GCC uses it for warning (the length for bounds and "static" for nonnull), so it starts to become useful.
- kazinator 5mo agoThe parentheses in (*parray)[i] would be unnecessary if dereferencing used postfix notation. Current: All postfix *ptr[3] ptr[3]* // indexed access, then deref (*ptr)[3] ptr*[3] // deref, then indexed access*
- geocar 5mo agoDereferencing does have a postfix notation, so you can try it (sort of): #define $ [0] then you can say ptr $[0] or ptr[0]$ and see if it's really better...