我正在处理具有多个地址空间的目标上的C ++代码。我想使用的代码有指向成员的指针:
struct foo {
int bar;
int baz;
};
typedef int foo::*foo_member;
foo_member m = &foo::bar;
#define AS1 __attribute__((address_space(1)))
int main()
{
foo AS1* f = /* ... */;
f->*m = 4;
}
到目前为止一切顺利。但是,当我试图获得指向实际成员的指针时,事情变得有趣:
int main()
{
foo AS1* f = /* ... */;
int AS1* x = &(f->*m);
}
Clang 3.7.0(标签/ RELEASE_370 / final)抱怨:
test.cpp:14:11: error: cannot initialize a variable of type
'__attribute__((address_space(1))) int *' with an rvalue of type 'int *'
int AS1* x = &(f->*m);
^ ~~~~~~~~
似乎地址运算符(或成员解除引用?)会丢弃地址空间限定符。
如何在确保地址空间不被删除的情况下使用指向具有地址空间的成员的指针?