HackerTrans
TopNewTrendsCommentsPastAskShowJobs

alurm

no profile record

Submissions

Nix Taco Sprint 2026

jrdsgl.com
6 points·by alurm·16 дней назад·0 comments

A generic dynamic array in C that stores no capacity and needs no struct

gist.github.com
27 points·by alurm·в прошлом месяце·33 comments

[untitled]

1 points·by alurm·2 месяца назад·0 comments

comments

alurm
·27 дней назад·discuss
Yeah, I've added macros `vec_len` and `vec_ptr` (or, enums, actually), which help somewhat.

`arr[3]` should be flagged by the compiler it is known to the compiler that you're operating on an array.

You can pass `arr` as `&arr` to functions, then compiler will know the length of the array since the type would be `T ()[2]`.

And you can then use it like this:

  void f(int *(*ints)[2]) {
      for (size_t i = 0; i < (size_t)vec_len[*ints]; i++) printf("f: %d\n", vec_ptr[*ints][i]);
  }
Curiously, this is a rare case where the "inverted" `a[b]` requires less typing compared to `(b)[a]`.

A compiler will not be able to flag `vec_len[ints]` though, which is unfortunate.
alurm
·27 дней назад·discuss
Thank you! I implemented this pattern initially about a year ago, but decided to write about it now. Since you liked it, it wasn't for nothing. :)
alurm
·27 дней назад·discuss
You're right, I added some more clarity in the README.

Interestingly, I think my approach will work fine on CHERI, since the pointer is never dereferenced, but I didn't test this. But yeah, there are some architectures where it would fail.
alurm
·27 дней назад·discuss
Good point! Added `vec_ptr[vec]` and `vec_len[vec]` helpers to mitigate this somewhat.
alurm
·27 дней назад·discuss
Thanks for mentioning it, I've heard about stb, but this time around I actually looked at the code. Their approach is very nice.
alurm
·4 месяца назад·discuss
Making a strict subset of some existing language (Go) be a "better C" is quite an interesting idea compared to others (D, Zig, Hare, C3, D, ...), haven't seen it elsewhere. No new syntax. And Go seems to be a pretty good choice for this. Not sure if it's gonna fly though.
alurm
·12 месяцев назад·discuss
Location: Yerevan, Armenia.

Remote: yes.

Willing to relocate: yes.

Technologies: Rust, C/C++, Bash, Go, Linux, Nix.

Résumé/CV: https://alurm.github.io/resume/alan-urmancheev.html (or .pdf for a PDF).

Email: [email protected].

A systems programmer. Prefer US opportunities.