logoalt Hacker News

wahern • today at 5:24 PM • 2 replies • view on HN

> Those language features are not examples of dependent types, though...

Ironically C is the only language in that list with a dependent type. It's not _Generic, of course, but variable-length arrays (VLAs), which neither C++, Rust, nor Zig have.


Replies

WalterBright • today at 5:44 PM

D has variable length arrays as a builtin type. They are extremely useful.

C VLAs are a terribly clumsy design. Here's the right way to do it in C:

https://www.digitalmars.com/articles/C-biggest-mistake.html

➕ show 1 reply
Someone • today at 7:18 PM

C also ‘supports’ fixed-length arrays. You can write

  int foo(int bar[10]) {
    …
  }
and you can tweak that to generate warnings when users pass arguments of the wrong size. See https://lwn.net/Articles/1046840/
➕ show 1 reply