错误C2059:在将c源文件添加到项目时,语法错误:“}”。

时间:2023-01-13 20:36:44

I'm writing a C++ application in visual studio express for windows phone 8.

我正在为windows phone 8在visual studio express中编写一个c++应用程序。

I'm trying to use flite, a text to speech library written in c, so far I've added its source files and headers, and I've set the option to use precompiled headers to no on all of the individual c files, However the source files still do not compile, instead the compiler complains (many times) :

我想用争吵,一个文本到语音图书馆用c编写的,到目前为止,我已经添加源文件和标题,和我设置的选项使用预编译头c任何在所有的个人文件,但是仍然不编译源文件,而不是编译器抱怨(多次):

 error C2059: syntax error : '.'
 error C2059: syntax error : '}'

It complains of these problems for this code in the flite source:

它在flite的源代码中抱怨这些代码的问题:

DEF_STATIC_CONST_VAL_STRING(ffeature_default_val,"0");

The definition of DEF_STATIC_CONST_VAL_STRING being:

DEF_STATIC_CONST_VAL_STRING的定义是:

#define DEF_CONST_VAL_STRING(N,S) const cst_val N = {{.a={.type=CST_VAL_TYPE_STRING,.ref_count=-1,.v={.vval= (void *)S}}}}

Here you can see the "." and "}" the compiler complains of. I've not modified the c source in anyway, and it builds for iOS and Android projects, so I'd assume I've not grasped how to include C files in visual express. On a side note, in Visual Express, the icons next to the .c files are "++" :/

在这里您可以看到“。”和“}”编译器抱怨。我还没有修改c源代码,它是为iOS和Android项目构建的,所以我假设我还没有掌握如何在visual express中包含c文件。另一方面,在visualexpress中,.c文件旁边的图标为“++”:/。

Any help is greatly appreciated.

非常感谢您的帮助。

2 个解决方案

#1


4  

This syntax:

这语法:

struct MyStruct someObject = {.foo = bar, .baz = quux};

is called designated initializers. It's only valid in the C99 dialect of C—it's invalid in C89 and in all versions of C++. Microsoft Visual Studio's C compiler is not C99-compliant, so it will not be able to compile that code. You must either convert the code to use C89 or C++, or use a different compiler which supports C99.

被称为指定初始值设定项。它只在C99方言中有效——在C89中是无效的,在所有版本的c++中都是无效的。Microsoft Visual Studio的C编译器不是c99兼容的,因此无法编译该代码。您必须转换代码以使用C89或c++,或者使用支持C99的不同编译器。

#2


2  

C99 initialization style (designated initializers) is not supported in C++, see here or here. In other words, { .blah = 42 }; is illegal in C++.

C99初始化样式(指定的初始化程序)在c++中不受支持,请参阅这里或这里。换句话说,{。blah = 42};在c++中是违法的。

What you can do is to create a C wrapper to this library, the file will be compiled in C but the functions will be available to C++ code. Note that msvc compiler does not support C99.

您可以做的是为这个库创建一个C包装器,该文件将在C中编译,但是函数将会提供给c++代码。注意,msvc编译器不支持C99。

#1


4  

This syntax:

这语法:

struct MyStruct someObject = {.foo = bar, .baz = quux};

is called designated initializers. It's only valid in the C99 dialect of C—it's invalid in C89 and in all versions of C++. Microsoft Visual Studio's C compiler is not C99-compliant, so it will not be able to compile that code. You must either convert the code to use C89 or C++, or use a different compiler which supports C99.

被称为指定初始值设定项。它只在C99方言中有效——在C89中是无效的,在所有版本的c++中都是无效的。Microsoft Visual Studio的C编译器不是c99兼容的,因此无法编译该代码。您必须转换代码以使用C89或c++,或者使用支持C99的不同编译器。

#2


2  

C99 initialization style (designated initializers) is not supported in C++, see here or here. In other words, { .blah = 42 }; is illegal in C++.

C99初始化样式(指定的初始化程序)在c++中不受支持,请参阅这里或这里。换句话说,{。blah = 42};在c++中是违法的。

What you can do is to create a C wrapper to this library, the file will be compiled in C but the functions will be available to C++ code. Note that msvc compiler does not support C99.

您可以做的是为这个库创建一个C包装器,该文件将在C中编译,但是函数将会提供给c++代码。注意,msvc编译器不支持C99。