Disabling bit padding interacts weirdly with structures

With a 2-byte file, containing the bytes 10 32, and this template:

BitfieldDisablePadding();

struct S {
	ubyte x : 4;
};

S s;
S s;

The variables tab will say that s[0] starts at 0x0, which is expected, and that s[1] starts at 0x1, which is not expected. However, the values are correct, with s[0].x being 0 and s[1].x being 1. Setting the start addresses to Local will show s[1].x starting at -1.

With this template:

BitfieldDisablePadding();

struct S {
	ubyte x : 4;
} s[2];

The value of s[0].x is still 0, but the value of s[1].x is now 2.

And finally, with this template:

BitfieldDisablePadding();

struct S {
	ubyte x : 4;
} s[4];

The error Template passed end of file. will be shown.

The expectation is that, for the first and second templates, the start addresses for s[0] and s[1] will both be 0x0, and for the third template, 4 s objects will be created, with the first two starting at 0x0 and having the values 0 and 1, and the last two starting at 0x1 and having the values 2 and 3.

You are correct that the starting address for s[1] is off by one, although the variables are being displayed in the correct position. We’ll try to get this fixed up in one of our next versions. When using an array of unpadded structs, you should be using <optimize=false> for this to work properly. For example:

BitfieldDisablePadding();

struct S {
	ubyte x : 4;
} s[4] <optimize=false>;

Later versions of 010 Editor should popup a warning dialog about optimizing issues when running your original code.

Graeme
SweetScape Software

Oops. I must have disabled this warning in the past and then completely forgot about the optimize attribute since. Sorry about that.