logoalt Hacker News

matheusmoreiratoday at 6:50 PM2 repliesview on HN

Amazing, this is a life saving feature for C developers. Apparently it's not complete yet? I will apply this to my code once the feature is included on LLVM and GCC.

Would be nice if the annotations could also be applied to structure fields.

  struct bytes {
      size_t count;
      unsigned char * __counted_by(count) pointer;
  };

  void work_with(struct bytes);

Replies

zokiertoday at 6:59 PM

counted_by for struct fields actually is actually the part that afaik works today: https://embeddedor.com/blog/2024/06/18/how-to-use-the-new-co...

show 1 reply
ueckertoday at 8:15 PM

Clang has this and upcoming GCC will also have this: https://godbolt.org/z/KETrPEnT1

show 1 reply