在Clang中使用指向成员的指针和地址空间

编程入门 行业动态 更新时间:2024-10-19 23:24:47
本文介绍了在Clang中使用指向成员的指针和地址空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在具有多个地址空间的目标上使用C ++代码。我想使用的代码具有指向成员的指针:

I'm working on C++ code on a target that has multiple address spaces. The code I would like to use has pointers to members:

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; }

到目前为止很好。但是,当我尝试获取指向实际成员的指针时,事情会变得很有趣:

So far so good. However, things get funny when I try to get a pointer to the actual member:

int main() { foo AS1* f = /* ... */; int AS1* x = &(f->*m); }

Clang 3.7.0(标签/ RELEASE_370 / final)抱怨:

Clang 3.7.0 (tags/RELEASE_370/final) complains:

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); ^ ~~~~~~~~

似乎地址的运算符(或取消成员引用?)删除地址空间限定符。

It seems that the address-of operator (or the member dereference?) drops the address space qualifier.

如何在确保不删除地址空间的同时使用指向具有地址空间的成员的指针?

How can I use pointers to members with address spaces while ensuring that the address space is not dropped?

推荐答案

这是一个编译器错误。 已报告,并且已提交了补丁。

It's a compiler bug. It's been reported and a patch has been submitted.

更多推荐

在Clang中使用指向成员的指针和地址空间

本文发布于:2023-07-29 00:45:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   成员   地址   空间   Clang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!