我有一个头文件,其类型定义如下
#ifndef SETSIZE
#define SETSIZE 32
#endif
typedef struct _set {
unsigned array[SETSIZE];
} set_t;
Run Code Online (Sandbox Code Playgroud)
要使用相应的C函数,我需要在Ada中使用set_t类型.问题是SETSIZE是一个可配置的参数(默认值为32).如果我理解正确,我无法访问Ada的预处理器定义.是否可以在c文件中添加一个常量并在Ada中使用它,如下所示:
#ifndef SETSIZE
#define SETSIZE 32
#endif
const size_t test = SETSIZE;
// Alternative
enum { test2 = SETSIZE };
--Ada--
-- import test somehow
type set_array is array (0 .. test) of aliased Interfaces.C.unsigned;
type set_t is record
array_field : aliased set_array;
end record;
Run Code Online (Sandbox Code Playgroud)
或者在Ada中正确使用此类型的任何其他方式,而无需在原始C代码中进行太多更改
在此答案中,提到了在即将到来的C ++ 20标准中可以使用usingon语句,enum class并将枚举字段导入本地名称空间。
我想知道这是否还意味着我也可以在这样的类定义中使用它:
class Foo {
enum class Color
{
red,
blue
};
using enum Color;
};
int main()
{
Foo::Color c = Foo::red;
}
Run Code Online (Sandbox Code Playgroud)
还是我仍然需要提供完整的名称空间?:
Foo::Color c = Foo::Color::red;
Run Code Online (Sandbox Code Playgroud)
我在wandbox.org中尝试过,但似乎gcc和clang都不知道using enum。