C2061 语法错误(标识符)

发布于 2024-09-16 15:06:11 字数 3771 浏览 7 评论 0原文

1>cb.c(51): error C2061: syntax error : identifier 'SaveConfiguration'
1>cb.c(51): error C2059: syntax error : ';'
1>cb.c(51): error C2059: syntax error : 'type'
1>cb.c(52): error C2061: syntax error : identifier 'LoadConfiguration'
1>cb.c(52): error C2059: syntax error : ';'
1>cb.c(52): error C2059: syntax error : 'type'
1>cb.c(122): error C2061: syntax error : identifier 'SaveConfiguration'
1>cb.c(122): error C2059: syntax error : ';'
1>cb.c(122): error C2059: syntax error : 'type'
1>cb.c(127): error C2061: syntax error : identifier 'LoadConfiguration'
1>cb.c(127): error C2059: syntax error : ';'
1>cb.c(127): error C2059: syntax error : 'type'
1>
1>Build FAILED.

它只是项目中的一个 .c 文件。代码如下:

#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <tchar.h>

typedef struct _Configuration
{
    int             KeyActivate;
    int             BlockWidth;
    int             BlockHeight;
    double          HueStart;
    double          HueEnd;
    double          SaturationStart;
    double          SaturationEnd;
    double          ValueStart;
    double          ValueEnd;
} Configuration;

typedef struct _DIBSection
{
    HDC     ScreenDC;
    HDC     WindowDC;
    HDC     MemoryDC;
    HBITMAP ScreenBMPHandle;
    BITMAP  ScreenBMP;
} DIBSection;

typedef struct _Thread
{
    HANDLE      Handle;
    unsigned    Id;
} Thread;

typedef struct _Window
{
    HANDLE  Handle;
    HDC     DC;
    int     Width;
    int     Height;
    int     Top;
    int     Left;
} Window;

__declspec ( dllexport ) int Initialize ( void );
unsigned __stdcall Start ( void * Arguments );

void LoadDefaultConfiguration ( Configuration * Config );
bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath );
bool LoadConfiguration ( Configuration * Config, LPTSTR FilePath );

Thread          MainThread;
Window          Screen;
Configuration   Settings;

BOOL WINAPI DllMain ( HINSTANCE Instance, DWORD Reason, LPVOID Reserved )
{
    switch ( Reason )
    {

        case DLL_PROCESS_ATTACH:

            // TODO: Load settings from file
            LoadDefaultConfiguration ( & Settings );

            // Create main thread
            MainThread.Handle = (HANDLE) _beginthreadex (
                NULL,
                0,
                Start,
                NULL,
                0,
                & MainThread.Id
                );

            if ( MainThread.Handle )
            {
                SetThreadPriority ( MainThread.Handle, THREAD_PRIORITY_BELOW_NORMAL );
            }
            else
            {
                MessageBox ( NULL, L"Unable to create main thread; exiting", L"Error", MB_OK );
                ExitProcess ( 0 );
            }

            break;

        case DLL_PROCESS_DETACH:

            break;

    }

    return TRUE;
}

__declspec ( dllexport ) int Initialize ( void )
{
    return 1;
}

unsigned __stdcall Start ( void * Arguments )
{
    return 1;
}

void LoadDefaultConfiguration ( Configuration * Config )
{
    Config->BlockHeight = 50;
    Config->BlockWidth = 100;
    Config->HueEnd = 0.00;
    Config->HueStart = 0.00;
    Config->KeyActivate = VK_SHIFT;
    Config->SaturationEnd = 0.00;
    Config->SaturationStart = 0.00;
    Config->ValueEnd = 0.00;
    Config->ValueStart = 0.00;
}

bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath )
{
    return true;
}

bool LoadConfiguration ( Configuration * Config, LPTSTR FilePath )
{
    return true;
}

第 51 行是

bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath );
1>cb.c(51): error C2061: syntax error : identifier 'SaveConfiguration'
1>cb.c(51): error C2059: syntax error : ';'
1>cb.c(51): error C2059: syntax error : 'type'
1>cb.c(52): error C2061: syntax error : identifier 'LoadConfiguration'
1>cb.c(52): error C2059: syntax error : ';'
1>cb.c(52): error C2059: syntax error : 'type'
1>cb.c(122): error C2061: syntax error : identifier 'SaveConfiguration'
1>cb.c(122): error C2059: syntax error : ';'
1>cb.c(122): error C2059: syntax error : 'type'
1>cb.c(127): error C2061: syntax error : identifier 'LoadConfiguration'
1>cb.c(127): error C2059: syntax error : ';'
1>cb.c(127): error C2059: syntax error : 'type'
1>
1>Build FAILED.

It's just a single .c file in the project. Here's the code:

#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <tchar.h>

typedef struct _Configuration
{
    int             KeyActivate;
    int             BlockWidth;
    int             BlockHeight;
    double          HueStart;
    double          HueEnd;
    double          SaturationStart;
    double          SaturationEnd;
    double          ValueStart;
    double          ValueEnd;
} Configuration;

typedef struct _DIBSection
{
    HDC     ScreenDC;
    HDC     WindowDC;
    HDC     MemoryDC;
    HBITMAP ScreenBMPHandle;
    BITMAP  ScreenBMP;
} DIBSection;

typedef struct _Thread
{
    HANDLE      Handle;
    unsigned    Id;
} Thread;

typedef struct _Window
{
    HANDLE  Handle;
    HDC     DC;
    int     Width;
    int     Height;
    int     Top;
    int     Left;
} Window;

__declspec ( dllexport ) int Initialize ( void );
unsigned __stdcall Start ( void * Arguments );

void LoadDefaultConfiguration ( Configuration * Config );
bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath );
bool LoadConfiguration ( Configuration * Config, LPTSTR FilePath );

Thread          MainThread;
Window          Screen;
Configuration   Settings;

BOOL WINAPI DllMain ( HINSTANCE Instance, DWORD Reason, LPVOID Reserved )
{
    switch ( Reason )
    {

        case DLL_PROCESS_ATTACH:

            // TODO: Load settings from file
            LoadDefaultConfiguration ( & Settings );

            // Create main thread
            MainThread.Handle = (HANDLE) _beginthreadex (
                NULL,
                0,
                Start,
                NULL,
                0,
                & MainThread.Id
                );

            if ( MainThread.Handle )
            {
                SetThreadPriority ( MainThread.Handle, THREAD_PRIORITY_BELOW_NORMAL );
            }
            else
            {
                MessageBox ( NULL, L"Unable to create main thread; exiting", L"Error", MB_OK );
                ExitProcess ( 0 );
            }

            break;

        case DLL_PROCESS_DETACH:

            break;

    }

    return TRUE;
}

__declspec ( dllexport ) int Initialize ( void )
{
    return 1;
}

unsigned __stdcall Start ( void * Arguments )
{
    return 1;
}

void LoadDefaultConfiguration ( Configuration * Config )
{
    Config->BlockHeight = 50;
    Config->BlockWidth = 100;
    Config->HueEnd = 0.00;
    Config->HueStart = 0.00;
    Config->KeyActivate = VK_SHIFT;
    Config->SaturationEnd = 0.00;
    Config->SaturationStart = 0.00;
    Config->ValueEnd = 0.00;
    Config->ValueStart = 0.00;
}

bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath )
{
    return true;
}

bool LoadConfiguration ( Configuration * Config, LPTSTR FilePath )
{
    return true;
}

Line 51 is

bool SaveConfiguration ( Configuration * Config, LPTSTR FilePath );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你爱我像她 2024-09-23 15:06:11

bool 不是 C 类型。

我确实怀疑 BOOL 是在某个地方定义的。

truefalse 的使用也是如此。

bool is not a C type.

I do suspect BOOL is defined somewhere.

Same goes for the usage of true and false.

两个我 2024-09-23 15:06:11

实际上,假设您使用的是最新的编译器,bool 是 C99 标准中的有效类型(实际上是宏)。您需要添加:

#include <stdbool.h>

请注意,bool 在旧版 ANSI、C89、C90 等 C 标准变体中无效。


正如 JeremyP 在评论中强调的那样,微软的 C 编译器仍然缺乏对 C99 功能的适当支持。

这就留下了三种选择:

  1. 将其视为 C++,而不是 C;因为 C++ 有 bool 作为内置类型
  2. 创建您自己的 bool 实现
  3. 重写代码以避免使用 bool

对于选项 2 类似这可行,但这是一个丑陋的解决方法:

typedef short bool;
#define true 1
#define false 0

Actually, bool is a valid type (well, a macro actually) in the C99 standard, assuming you are using a recent compiler. You need to add:

#include <stdbool.h>

Note that bool is not valid in the older ANSI, C89, C90 etc variants of the C standards.


As highlighted by JeremyP in the comments, Microsoft's C compiler still lacks proper support for C99 features.

Which leaves three alternatives:

  1. Treat it as C++, not C; because C++ has bool as a built-in type
  2. Create your own bool implementation
  3. Re-write the code to avoid using bool

For option 2 something like this would work, but it's an ugly work-around:

typedef short bool;
#define true 1
#define false 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文