【发布时间】:2014-06-02 02:21:39
【问题描述】:
我有一个 .c 文件,我正在尝试在 VS2012 中编译,但我收到此错误:
error C2059: syntax error : '.' main.c
根据我读到的内容,这是 VS2012 编译器的一个特定问题,我不会在其他编译器中遇到这个问题。不管这是否属实,我希望这里有人能告诉我如何修复这个编译器错误。如何修改代码,使代码能够编译并且行为相同?
这是我的头文件中的内容:
struct mystruct
{
struct someOtherStruct obj2;
void* ptr1;
void* ptr2;
void* ptr3;
};
这就是我在 main.c 中的内容
void* P1 = NULL;
void* P2 = NULL;
void* P3 = NULL;
/* VS2012 complains about this syntax */
static struct mystruct obj =
{
.ptr1 = P1,
.ptr2 = P2,
.ptr3 = P3,
};
void main(void)
{
/* Empty for now */
}
【问题讨论】:
-
在初始化结构时使用成员名称是 C 的“最新”版本的一个特性。C 编译器似乎有点落后于时代,因为它不能识别最新的语法,所以使用较旧的语法,如@Praetorian 所示。所有 C 编译器仍支持旧语法。
标签: c visual-studio-2012 gcc struct