checkedc
checkedc copied to clipboard
Struct pointer arithmetic
I have the following code:
typedef struct {
char z;
} A;
typedef struct {
A a;
} B;
void func(A *a) {
B *b = (B*)((char*)a - offsetof(B, a));
}
int main() {
B b;
func(&b.a);
}
What is the best way to convert this into Checked C? For function func
, it doesn't make sense to make a
as and _Array_ptr
of count 1 since the calculation afterward will go beyond its bounds.