3 ms·
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
by matheusmoreira 9mo ago
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);
- zokier 9mo agocounted_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-counted_by-attribute-in-c-and-linux/ https://embeddedor.com/blog/2024/06/18/how-to-use-the-new-co...
- matheusmoreira 9mo agoThat's amazing. Thanks for that reference. If it's good enough for the kernel, then it's good enough for me to start using in my own projects. It's really cool that the kernel is using this. The compiler must be generating simple bounds checking code with traps instead of crazy stuff involving magical C standard library functions. Perfect for freestanding nostdlib projects.
- uecker 9mo agoClang has this and upcoming GCC will also have this: https://godbolt.org/z/KETrPEnT1 https://godbolt.org/z/KETrPEnT1
- matheusmoreira 9mo agoThis is awesome!!