[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] will touch memory past end of the struct
From: |
Quentin Carbonneaux |
Subject: |
Re: [Tinycc-devel] will touch memory past end of the struct |
Date: |
Mon, 15 May 2017 16:05:17 +0000 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Hi,
>From a quick test with tcc, it looks like the
bitfield will be allocated the last 16 bits of
the struct. When accessing it, tcc generates code
that loads a full 'unsigned int', hence loading
(or writing) 2 bytes after the end of the struct.
Not sure if that answers the question.
By the way, I use bitfields pretty extensively in
my compiler (https://c9x.me/compile/), and it looks
like C99 compound literals are not quite working
yet with those. For example, the following program
fails to compile:
struct S {
int x: 2;
int y: 30;
};
int f()
{
struct S x = {1, 2};
return (struct S[]){x, {0, 0}}[1].y;
}
Best,
--
Quentin