问题描述
大家好,我有这样的问题:
guys, I've this problem:
通常,在C99 GCC(Cygwin的/ MinGW的/ Linux的),对于在C结构初始化点表示法语法。结果
像这样的:
Normally in C99 GCC (cygwin / MinGW / linux), there is dot-notation syntax for initializers in C struct.
Like this:
//HELP ME HOW TO REWRITE THIS (in most compact way) to MSVC
static struct my_member_t my_global_three[] = {
{.type = NULL, .name = "one"},
{.type = NULL, .name = "two"},
{.type = NULL, .name = "three"},
};
有 my_memeber_t
在头文件中定义为:
struct my_member_t {
struct complex_type * type;
char * name;
int default_number;
void * opaque;
};
我在编译的 MSVC 9.0 (Visual Studio 2008中),在Cygwin / MinGW的该工程确定的linux code。结果
但 CL 无法编译这个(因为惨C99实现):错误C2059:语法错误:。
I'm compiling linux code in MSVC 9.0 (Visual Studio 2008), on cygwin/MinGW this works ok.
BUT cl is unable to compile this (because of miserable C99 implementation): error C2059: syntax error : '.'
问题:结果
的
如何重写的方式(很多)的全球结构的MSVC (RESP C89)
可以编译它?
的
有关建议最好的问候和感谢...
Best regards and thanks for suggestions...
推荐答案
惨C99实现?我不认为C编译器VC2008甚至尝试实现C99。它可能借用一些功能,但它确实是一个C89 / 90的编译器。
Miserable C99 implementation? I don't think that C compiler in VC2008 even tries to implement C99. It might borrow some features, but it is really a C89/90 compiler.
刚落,现场名称标签
static struct my_member_t my_global_three[] = {
{ NULL, "one"},
{ NULL, "two"},
{ NULL, "three"},
};
在此情况下,它是很容易的,因为在初始化的原code中的次序是一样的,在结构域的顺序。如果订单是不同的,你必须重新排列在无标签C89 / 90版本。
In this case it is easy, since the order of the initializers in the original code is the same as the order of fields in the struct. If the order was different, you'd have to rearrange them in the tagless C89/90 version.
如果这是真的的您的 my_member_t
,那么应该声明字符串指针为为const char *
或停止初始化这些成员字符串。
And if it's really your my_member_t
, then you should either declare the string pointer as const char *
or stop initializing these members with string literals.
这篇关于如何重写C-结构指定初始化为C89(RESP MSVC C编译器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!