Hacker News new | ask | show | jobs
by Joker_vD 1 day ago
> "str is an array 10 of pointers to char"

Wow, imagine if it was possible to actually use a language like that do declare the type of the variable like that? Something like

    str: array [0..9] of ^Char; 
or even

    var str [10]*uint8
Just imagine...
2 comments

Yeah, Pascal is very readable, and ^Char is nicer than char* even if inconsistently concise (might expect "pointer to Char").
Or even

  var str: array[10, ptr char]
Eh, or that, I guess. I personally would rather not squish the type of the elements together with the dimensions, but it can work like that, sure. Especially if you use square brackets for generic instantiation, so your example is semantically close to std::array<char*, 10> of C++. But if the language uses the square brackets (almost) exclusively for array indexing, then having simply "[10]" prefix as a shorthand for "array of 10 of ..." à la Zig/Go is quite reasonable. Then again, Go does use square brackets both for instantiation of generics and for array-related operations so... I guess they had the syntax of map types as a precedent.
> Especially if you use square brackets for generic instantiation, so your example is semantically close to std::array<char*, 10> of C++.

Yes, it is like that.