4 ms·
It's a C99 variable-length array declaration, so the syntax is valid; but unfortunately it doesn't actually do anything useful. The 'const unsigned char data[
by kiwidrew 6y ago
It's a C99 variable-length array declaration, so the syntax is valid; but unfortunately it doesn't actually do anything useful. The 'const unsigned char data[len]' declaration just decays to 'const unsigned char *data' -- the first level of array-ness is discarded.
[ there was a bit of discussion about this earlier in the month: https://news.ycombinator.com/item?id=26349903 https://news.ycombinator.com/item?id=26349903 ]
- h_anna_h 6y agoIt is useful for static analysis, even the standard people say that they will move into this kind of declaration. > 15. Application Programming Interfaces (APIs) should be self-documenting when possible. In particular, the order of parameters in function declarations should be arranged such that the size of an array appears before the array. The purpose is to allow Variable-Length Array (VLA) notation to be used. This not only makes the code's purpose clearer to human readers, but also makes static analysis easier. Any new APIs added to the Standard should take this into consideration. from http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm
- pjmlp 6y agoWhich was dropped in C11, with clang and gcc probably being the only C compilers on Earth that might still support it on C11 and C17 mode.
- h_anna_h 6y agoIt was not dropped. VLAs were deemed as optional but (if I am not mistaken) this specific syntax is not optional, only local VLA declarations. > with clang and gcc probably being the only C compilers on Earth that might still support it on C11 and C17 mode Are there any other C11 compilers even?
- pjmlp 6y agoDeemed as optional is a synomim for dropped to any compiler that is yet to fully implement them, as they aren't required to support it for ISO C certification. Several commercial compilers for embedded development, mainframes and surviving UNIXes, VC2019 since 16.8. Additionally ICC apparently never supported VLAs that well.