Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
witch_t *navi
@navi@social.vlhl.dev  ·  activity timestamp 2 months ago
@mirabilos not ever (though i do bsearch somewhat often), which is why i want more ways to do vla-types, for a dynamic array btw, you can do:
int (*arrayp)[len] = malloc(sizeof(*arrayp));
/* init *arrayp */
qsort_typed(*arrayp, cmp, data);

or, what could be more useful, say you have a struct type:

struct int_array { size_t len; int *data };
#define to_vla(arr) ((int (*)[arr.len]) arr.data)

struct int_array my_ints = ...;
qsort_typed(*to_vla(my_ints), compare, data);

and it’s the reason i really wish we add a way to specify VLA syntax in structures, so we could end up with something similar to:

struct int_array { size_t len; int (*data)[len]; };

struct int_array my_ints = ...;
qsort_typed(*my_ints.data, compare, data);
  • Copy link
  • Flag this post
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.3.5 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login