是否允许在模板类的静态成员上使用__attribute __((section(“.something"))))? [英] is __attribute__((section(".something"))) on a static member of a template class allowed?

查看:36
本文介绍了是否允许在模板类的静态成员上使用__attribute __((section(“.something"))))?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

lang将相应的变量正确地放置在'.aaa'和'.ggg'中.GCC在'.ggg'上工作,但在'.aaa'(类模板的静态成员变量)上不工作.

in the following example clang puts the respective variables in '.aaa' and '.ggg' correctly. GCC works on '.ggg' but not on '.aaa' (the static member variable of the class template).

template<int I>
struct s{
    __attribute__((section(".aaa"))) static  int a[100];
};

__attribute__((section(".ggg"))) int  b[100]; 

template<int I>
__attribute__((section(".aaa"))) int s<I>::a[100];

这是CCC漏洞还是clang的自愿支持?

Is this a GCC bug or voluntary support on the part of clang?

是否有很好的解决方法(除了使s :: a为全局成员,而不是静态成员)?

Is there a good work around (besides making s::a a global rather than a static member)?

注意:我遗漏了编译器版本,因为Godbolt上的所有GCC版本实际上都做同样的事情 https://godbolt.org/g/E5s0mi

note: I left out the compiler version as all version of GCC on godbolt do essentially the same thing https://godbolt.org/g/E5s0mi

推荐答案

gcc的官方文档说

将section属性与全局变量而不是局部变量一起使用,如示例所示.

Use the section attribute with global variables and not local variables, as shown in the example.

本地链接=错误?如果类本身是本地的,则静态成员变量是本地的.我会通过模板声明说它的本地性.

local linkage = wrong? static member variables are local if the class itself is local. and i would say its local through the template declaration.

来源

这篇关于是否允许在模板类的静态成员上使用__attribute __((section(“.something"))))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆