aligned struct field weirdness
realhet
real_het at hotmail.com
Mon Jun 17 19:45:18 UTC 2024
Hello,
I'm having a weird case of access violation.
I tried to narrow the problem and put up a reproducible testCase
on compilerexploer, but it requires my framework too which
overrides std.stdio.writeln() in order to produce colorful text,
and logging, etc.
The error is an access violation when I access the struct in the
f() function.
Sometimes it can be fixed (marked the place.)
In one sentence: It is an aligned struct field, whose struct is
given to a class as a template parameter.
Maybe the weirdness is caused by the align(16)? When the fields
of the struct are placed on the instance of the class?
I know it's not reproduceable, maybe it was a bug that had been
already fixed. So I only ask if the situation is familiar to
someone, please tell me, what tricks I need to avoid.
I can avoid the align using dummy fields.
I can allocate the struct with new.
But it's a bummer, that the nicest version is unstable.
```
import het;
struct S
{
int a;
align(16)//<-this triggers it
int[4] b;
}
class A(T)
{
version(none)
{ T u; }
else
{
T* p; //<- this fixes it. (The struct is not on the class
surface)
ref u() { return *p; }
this() { p = new T; }
}
}
class B: A!S
{ void f() { writeln(u.text/+<-The access violation can be
here+/); } }
void main()
{
//writeln("a"); <- this fixes it
auto b = new B; //<-scoped! can trigger it too
b.f;
}
```
Thank You in advance.
More information about the Digitalmars-d-learn
mailing list