Live data from Hacker News

C array types are weird

anselmschueler.com

21–30 of 148 posts

Re: C array types are weird

#23
There is a history to it; in one of the predecessor languages, like B, Ritchie actually had arrays that had a hidden pointer to their start. The "array to pointer decay" was actually a real operation that loaded an address from memory, and it was possible to twiddle the bits to relocate an array. One problem with it was no way to initialize such a pointer field that would allow an array to live in dynamically allocated storage (no constructors in the language).

So in short, the bad design (array values produce pointers) was informed by conceptual compability with an earlier design in which that was literally happening.

Re: C array types are weird

#25
post #24

Earlier quoted context omitted.

https://www.tiobe.com/tiobe-index/

As always, the TIOBE Index is of dubious value. The fact that it ranks Delphi above both Go and Rust should give you an idea of why.

Yeah it's rather odd, also jumps like this in ADA makes you wonder

https://www.tiobe.com/tiobe-index/ada/

Re: C array types are weird

#26
C array types are weird because C doesn't really need arrays. It's not what C was about.

But if you designed a language in the era where Fortran, THE array language, reigned supreme, nobody would use your language. The mindshare Fortran had is difficult to convey now, half a century later.

Think of it like making a chatbot today and not mentioning AI or LLMs, that's what making a language without arrays would have felt like in 1970.

Re: C array types are weird

#28
post #9

Earlier quoted context omitted.

This talk – "Programming without pointers" – by Andrew Kelley may be interesting to you. https://www.hytradboi.com/2025/05c72e39-c07e-41bc-ac40-85e83...

Learning to program with pointers is enormously useful. It's simply bad software engineering to not use typing to enforce constraints on access to pointers (or addresses, or however you'd like to term them)

IIRC that talk of about using indices (u32) to represent data in an array. That is orthogonal to representing that information in the type system since you can just type the index

Re: C array types are weird

#29
post #6

Paging walter bright

C's biggest mistake. But in other news most don't know that a[3] == 3[a]

I didn't understand why a[3] == 3[a], but i found this stackoverflow that explains it.

https://stackoverflow.com/a/16163840

In C a[i] is converted to *(a+i) internally. i[a] is converted to *(i+a). Array names also act as pointers in c. so (a+i) or (i+a) give an address (using pointer arithmetic) that is dereferenced using

Post reply on HN