(Overlaying Structures): Fix the example to iniialize p. Clarify text.

This commit is contained in:
Richard Stallman 2022-09-30 12:58:48 -04:00
parent 6eeb5e1743
commit 6010acc42a
1 changed files with 6 additions and 5 deletions

11
c.texi
View File

@ -6391,6 +6391,7 @@ aliasing that can cause the problem:
struct a @{ int size; char *data; @}; struct a @{ int size; char *data; @};
struct b @{ int size; char *data; @}; struct b @{ int size; char *data; @};
struct a foo; struct a foo;
struct a *p = &foo;
struct b *q = (struct b *) &foo; struct b *q = (struct b *) &foo;
@end example @end example
@ -6408,12 +6409,12 @@ x = p->size;
@noindent @noindent
allows GNU C to assume that @code{p->size} is still zero when it is allows GNU C to assume that @code{p->size} is still zero when it is
copied into @code{x}. The compiler ``knows'' that @code{q} points to copied into @code{x}. The GNU C compiler ``knows'' that @code{q}
a @code{struct b} and this cannot overlap with a @code{struct a}. points to a @code{struct b} and this is not supposed to overlap with a
@code{struct a}. Other compilers might also do this optimization.
Other compilers might also do this optimization. The ISO C standard The ISO C standard considers such code erroneous, precisely so that
considers such code erroneous, precisely so that this optimization this optimization will not be incorrect.
will be valid.
@node Structure Assignment @node Structure Assignment
@section Structure Assignment @section Structure Assignment