https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86259

--- Comment #28 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
(In reply to Davin McCall from comment #27)
> Again, there was no pointer arithmetic (other than the line containing
> 'strlen', but that particular case the pointer has the address of the union
> object, which has been cast to (char *), and the '+ 4' should be valid then,
> surely, by 6.3.2.7 paragraph 7 (ignoring that it requires 'successive
> increments' rather than arbitrary addition, or is that supposed to be
> significant?).

Can someone explain why the example in comment #21 works when
pointer arithmentic instead of integer arithmetic is used?

char *sp_ip = (char *)bp - offsetof(struct S,b);
strcpy(u.xx, "abcdefghijk");
size_t len = strlen((char *)(union U*)sp_ip + 4);
puts(len == 7 ? "YES" : "NO");

prints "YES"

Reply via email to