checkedc icon indicating copy to clipboard operation
checkedc copied to clipboard

Struct pointer arithmetic

Open souragc opened this issue 5 months ago • 2 comments

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.

souragc avatar Sep 12 '24 14:09 souragc