E
Ersek, Laszlo
Hi,
with reference to [0] and [1], please consider the following:
1 #include <string.h>
2 #include <stdlib.h>
3
4 struct x {
5 double *y;
6 };
7
8 int
9 main(void)
10 {
11 struct x *x = malloc(sizeof *x);
12
13 /* suppose the allocation succeeds */
14 (void)memset(x, 0, sizeof *x);
15 (void)(0 == x->y);
16 return 0;
17 }
In my understanding, the evaluation of x->y on line 15 is undefined
behavior in C99.
Consider the following (fictious) extension:
"The all-bits-zero object representation is valid for any
pointer-to-object type. Any pointer-to-object object with the
all-bits-zero representation is a null pointer of the corresponding
pointer-to-object type."
Would this extension make the above program well defined?
In particular, would the following program still break aliasing rules, as
per C99 6.5 p 6-7?
1 #include <stdlib.h>
2
3 int
4 main(void)
5 {
6 double **d = malloc(sizeof *d);
7 size_t pos;
8
9 /* suppose the allocation succeeded */
10
11 for (pos = 0u; pos < sizeof *d; ++pos) {
12 ((char unsigned *)d)[pos] = 0u;
13 }
14
15 (void)*d;
16 return 0;
17 }
(I hope my question corresponds precisely to the austin-group-l topic.)
Thank you very much,
lacos
[0] https://www.opengroup.org/sophocles...tpl&source=L&listname=austin-group-l&id=13687
[1] https://www.opengroup.org/sophocles...tpl&source=L&listname=austin-group-l&id=13690
with reference to [0] and [1], please consider the following:
1 #include <string.h>
2 #include <stdlib.h>
3
4 struct x {
5 double *y;
6 };
7
8 int
9 main(void)
10 {
11 struct x *x = malloc(sizeof *x);
12
13 /* suppose the allocation succeeds */
14 (void)memset(x, 0, sizeof *x);
15 (void)(0 == x->y);
16 return 0;
17 }
In my understanding, the evaluation of x->y on line 15 is undefined
behavior in C99.
Consider the following (fictious) extension:
"The all-bits-zero object representation is valid for any
pointer-to-object type. Any pointer-to-object object with the
all-bits-zero representation is a null pointer of the corresponding
pointer-to-object type."
Would this extension make the above program well defined?
In particular, would the following program still break aliasing rules, as
per C99 6.5 p 6-7?
1 #include <stdlib.h>
2
3 int
4 main(void)
5 {
6 double **d = malloc(sizeof *d);
7 size_t pos;
8
9 /* suppose the allocation succeeded */
10
11 for (pos = 0u; pos < sizeof *d; ++pos) {
12 ((char unsigned *)d)[pos] = 0u;
13 }
14
15 (void)*d;
16 return 0;
17 }
(I hope my question corresponds precisely to the austin-group-l topic.)
Thank you very much,
lacos
[0] https://www.opengroup.org/sophocles...tpl&source=L&listname=austin-group-l&id=13687
[1] https://www.opengroup.org/sophocles...tpl&source=L&listname=austin-group-l&id=13690