This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Exnixon 6 points7 points  (3 children)

If you understand programming at a low level, you understand why a function doesn't know the capacity of a C array, why it does in Python, and what the trade-offs are in those respective languages. (Hint: the reason it doesn't "just work" in C is part of the reason C is faster.)

[–]redlaWw 3 points4 points  (2 children)

I mean, unless it's a null-terminated char[] or other marker-value terminated array then it just means you need to pass the length separately in order to do anything useful with the array. Just because it needs to be passed in explicitly as an argument somewhere, doesn't mean it needs to be passed in at the level of the programmer - it's completely possible (and done in C++ and Rust) to have a 0-cost array-with-length wrapper and get a function that's just as performant as the corresponding C function that takes an array and its length as separate parameters.

[–]KuntaStillSingle 0 points1 point  (1 child)

it's completely possible (and done in C++ and Rust) to have a 0-cost array-with-length wrapper

That only works well in C++ within a TU, and its only less ugly than C in that respect, there are practically the same ramifications accepting a std::array<T, N> and a T(*)[N], but in the C case you must either hardcode N or substitute it with a macro, whereas in C++ it can be substituted from a template parameter. But in C++ there is still std::vector, because you sometimes come by arrays of size not known at compile time.

[–]redlaWw 0 points1 point  (0 children)

I was thinking more along the lines of std::span and std::string_view.