Sujet : Re: Computer architects leaving Intel...
De : tkoenig (at) *nospam* netcologne.de (Thomas Koenig)
Groupes : comp.archDate : 15. Sep 2024, 14:30:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vc6k0u$25mru$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : slrn/1.0.3 (Linux)
Waldek Hebisch <
antispam@fricas.org> schrieb:
[...]
struct {
char x[8]
int y;
} bar;
bar.y = 0; bar.x[8] = 42;
IMHO, here behavior should be fully defined by implementation. And
in practice it is. Just not in theory.
That has two drawbacks: minor one that you need to know that
there are no padding between 'x' and 'y'.
Similar to Fortran's problems with unaligned variables in COMMON
blocks.
Major drawback
is that it would forbid bounds checking for array accesses.
In code like above it is easy to spot out of bound access at
compile time.
And it happens:
$ cat x.c
struct {
char x[8];
int y;
} bar;
void foo()
{
bar.y = 0;
bar.x[8] = 42;
}
$ gcc -O2 -c x.c
x.c: In function 'foo':
x.c:10:12: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
10 | bar.x[8] = 42;
| ~~~~~~~~~^~~~
x.c:3:9: note: at offset 8 into destination object 'x' of size 8
3 | char x[8];
| ^