| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1835 人关注过本帖
标题:C语言程序出现下面的错误“syntax error”,原因不明,请指教?
只看楼主 加入收藏
wjk_0713
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-5-19
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:6 
C语言程序出现下面的错误“syntax error”,原因不明,请指教?
源程序如下:
#include <iostream.h>

/*****************************************************************************************************
                                           宏定义
*****************************************************************************************************/

#define SDDETECT_MASK_SHIFT_BIT_BODY   (0x01<<9)
#define SCANEKY_MASK_GPIO_BODY         (0x7F)
#define HPHONE_MASK_SHIFT_BIT_BODY     (0x01<<7)
#define HOLDKEY_MASK_SHIFT_BIT_BODY    (0x01<<8)
#define SCANEKY_MASK_GPIO2_BODY        (0x01)
#define NUMBER_PICTURE_DEVISE_GPIO     (2)
#define LONGKEY_MINOR_ADJUST_TICKS     (10)
#define EOK                            (0)
#define DEFAULT_HOLDKEY_VALID_GPIO     (16)

/*****************************************************************************************************
                                          结构体定义
*****************************************************************************************************/

typedef int (*KeyPostProc)(unsigned int aScanCode, unsigned int stamp);

typedef struct Button_s
{
    unsigned int uiNumHigh;/* store number of bit is 1 of gpio button */
    unsigned int uiCurrPressed; /* remember pressed bits of gpio */
    unsigned int pauiHoldTicks[DEFAULT_HOLDKEY_VALID_GPIO];/* store hold down ticks for each button, +1, is for unused redundant only */
}Button_t;

typedef struct SensorOps_s
{
     int (*pfInitDev)(unsigned int);
     int (*pfPwr)(int iSwitch);
     int (*pfReset)(int iSwitch);
     unsigned int uiSetValue;
}SensorOps_st;

typedef struct ProductModel_s
{
    int (*initRoot)(void);
    int (*initSdDetect)(void);
    int (*isSdCardPresent)(void);
    int (*setSpeaker)(int);
    void (*getPictdev)(SensorOps_st **pstData);
    void (*getButton)(int group, Button_t **pstData);
    void (*gpio0Irq)(unsigned int pendIrq, KeyPostProc pfPostMsg);
    void (*gpio1Irq)(unsigned int pendIrq, KeyPostProc pfPostMsg);
    void (*longkeyNotify)(Button_t *pstBt0,  Button_t *pstBt1);
    int (*initHpDetect)(void);
    char *pcName;
}ProductModel_st;

/*****************************************************************************************************
                                          变量定义
*****************************************************************************************************/

static int g_iIgnoreHpIrq=1;
static volatile unsigned int g_uiGpioLongkeyTicks;
static unsigned int g_uiSdDetInited=0;
static unsigned int g_uiIsCustomed=0;
static unsigned int g_uiButtonInited_Jxd=0;

Button_t g_stGpioButtons ;
Button_t g_stGpioButtons2;

static SensorOps_st g_pastPictDev638[NUMBER_PICTURE_DEVISE_GPIO];

static ProductModel_st g_stJxd638;

/*****************************************************************************************************
                                          函数声明
*****************************************************************************************************/

static void gpio0Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg);
static void gpio1Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg);
static void sdDetect_dsr_Jxd638(void);
static void holdkey_dsr_Jxd638(void);
static void HpDetect_dsr_Jxd638(void);

static void longkeyNotify_Jxd638(Button_t *pstBt0,  Button_t *pstBt1);

static void keyscanGp0_dsr_Jxd638( KeyPostProc pfPostMsg);
static void keyscanGp1_dsr_Jxd638( KeyPostProc pfPostMsg);

static void initHeadPhone_GPIO_Jxd638(void);

static void getButton_Jxd638(int group, Button_t **pstData);
static void getPictdev_Jxd638(SensorOps_st **pstData);
static int isSDPlugIn_Jxd638(void );

static int initPictureDevOps_638(SensorOps_st *pstPictDev);
static int initBDISP_638(void);
static int initGpioButton_638(void);

static int initSDDetect_Jxd638(void);
static void initHeadPhone_GPIO_Jxd638(void);
static int initHoldKey_GPIO_Jxd638(void);
static int initCustom_GPIO_Jxd638(void);
int setSpkmute_SAR_JxdComm(int val);
int init_Jxd638(void);

/*****************************************************************************************************
                                          函数定义
*****************************************************************************************************/

static void gpio0Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg)
{
    if (pendIrq & SDDETECT_MASK_SHIFT_BIT_BODY)
    {
    sdDetect_dsr_Jxd638();
    }
    if (pendIrq & SCANEKY_MASK_GPIO_BODY)
        {
            keyscanGp0_dsr_Jxd638(pfPostMsg);
        }               

    if (pendIrq & HPHONE_MASK_SHIFT_BIT_BODY)
        {
            HpDetect_dsr_Jxd638();
        }
   
    if (pendIrq & HOLDKEY_MASK_SHIFT_BIT_BODY)
        {
            holdkey_dsr_Jxd638();
        }   

}

//============================================================================================

static void gpio1Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg)
{
        if (pendIrq & SCANEKY_MASK_GPIO2_BODY)
        {
            keyscanGp1_dsr_Jxd638(pfPostMsg);
        }
}

//============================================================================================

static void sdDetect_dsr_Jxd638(void){;}
static void holdkey_dsr_Jxd638(void){;}
static void HpDetect_dsr_Jxd638(void){;}
static void longkeyNotify_Jxd638(Button_t *pstBt0,  Button_t *pstBt1){;}
static void keyscanGp0_dsr_Jxd638( KeyPostProc pfPostMsg){;}
static void keyscanGp1_dsr_Jxd638( KeyPostProc pfPostMsg){;}
static void initHeadPhone_GPIO_Jxd638(void){;}
static void getButton_Jxd638(int group, Button_t **pstData){;}
static void getPictdev_Jxd638(SensorOps_st **pstData){;}
static int isSDPlugIn_Jxd638(void ){return 0;}
static int initPictureDevOps_638(SensorOps_st *pstPictDev){return 0;}
static int initBDISP_638(void){return 0;}
static int initGpioButton_638(void){return 0;}
static int initSDDetect_Jxd638(void){return 0;}
static int initHoldKey_GPIO_Jxd638(void){return 0;}
int setSpkmute_SAR_JxdComm(int val){return 0;}
static int initCustom_GPIO_Jxd638(void){return 0;}

//=============================================================================================

int init_Jxd638(void)
{
    if(g_uiIsCustomed)
    {   
        cout<<"init_Jxd638() already init \n";
        return 0;
    }


    initGpioButton_638();
    initBDISP_638();        


    initSDDetect_Jxd638();

    initHeadPhone_GPIO_Jxd638();   

    initHoldKey_GPIO_Jxd638();

    initPictureDevOps_638(g_pastPictDev638);

    g_uiGpioLongkeyTicks =LONGKEY_MINOR_ADJUST_TICKS;
   
        
    cout<<"initCustom_Jxd638() OK \n";   

    g_uiIsCustomed++;

    return EOK;
}
/*****************************************************************************************************
                                          主函数定义
*****************************************************************************************************/

int main(void)
{
    int ret;

    g_stJxd638={
        .initRoot = initCustom_GPIO_Jxd638,   
        .initSdDetect = initSDDetect_Jxd638,
        .getPictdev = getPictdev_Jxd638,
        .getButton = getButton_Jxd638,
        .setSpeaker= setSpkmute_SAR_JxdComm,
        .isSdCardPresent= isSDPlugIn_Jxd638,

        .longkeyNotify= longkeyNotify_Jxd638,

        .gpio0Irq = gpio0Irq_dsr_Jxd638,
        .gpio1Irq = gpio1Irq_dsr_Jxd638,
        .initHpDetect= initHeadPhone_GPIO_Jxd638,
        .pcName="Jxd 638"
        };

    ret=init_Jxd638();
    return ret;
}
编译后出现如下错误:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
F:\VC6\Cpp1.cpp(200) : error C2059: syntax error : '{'
F:\VC6\Cpp1.cpp(200) : error C2143: syntax error : missing ';' before '{'
F:\VC6\Cpp1.cpp(201) : error C2143: syntax error : missing ';' before '.'
执行 cl.exe 时出错.

Cpp1.obj - 1 error(s), 0 warning(s)

菜鸟请教明白人指点下,错在什么地方?
搜索更多相关主题的帖子: syntax error C语言 指教 
2010-05-19 19:23
wjk_0713
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-5-19
收藏
得分:0 
追加程序:
上面的错误自己已经找到,但是接下来编译成功后连接又有错误,在请教:
程序如下:
//#include <stdio.h>
#include <iostream.h>

/*****************************************************************************************************
                                           宏定义
*****************************************************************************************************/

#define SDDETECT_MASK_SHIFT_BIT_BODY   (0x01<<9)
#define SCANEKY_MASK_GPIO_BODY         (0x7F)
#define HPHONE_MASK_SHIFT_BIT_BODY     (0x01<<7)
#define HOLDKEY_MASK_SHIFT_BIT_BODY    (0x01<<8)
#define SCANEKY_MASK_GPIO2_BODY        (0x01)
#define NUMBER_PICTURE_DEVISE_GPIO     (2)
#define LONGKEY_MINOR_ADJUST_TICKS     (10)
#define EOK                            (0)
#define DEFAULT_HOLDKEY_VALID_GPIO     (16)

/*****************************************************************************************************
                                          结构体定义
*****************************************************************************************************/

typedef int (*KeyPostProc)(unsigned int aScanCode, unsigned int stamp);

typedef struct Button_s
{
    unsigned int uiNumHigh;/* store number of bit is 1 of gpio button */
    unsigned int uiCurrPressed; /* remember pressed bits of gpio */
    unsigned int pauiHoldTicks[DEFAULT_HOLDKEY_VALID_GPIO];/* store hold down ticks for each button, +1, is for unused redundant only */
}Button_t;

typedef struct SensorOps_s
{
     int (*pfInitDev)(unsigned int);
     int (*pfPwr)(int iSwitch);
     int (*pfReset)(int iSwitch);
     unsigned int uiSetValue;
}SensorOps_st;

typedef struct ProductModel_s
{
    int (*initRoot)(void);
    int (*initSdDetect)(void);
    int (*isSdCardPresent)(void);
    int (*setSpeaker)(int);
    void (*getPictdev)(SensorOps_st **pstData);
    void (*getButton)(int group, Button_t **pstData);
    void (*gpio0Irq)(unsigned int pendIrq, KeyPostProc pfPostMsg);
    void (*gpio1Irq)(unsigned int pendIrq, KeyPostProc pfPostMsg);
    void (*longkeyNotify)(Button_t *pstBt0,  Button_t *pstBt1);
    int (*initHpDetect)(void);
    char *pcName;
}ProductModel_st;

/*****************************************************************************************************
                                          变量定义
*****************************************************************************************************/

static int g_iIgnoreHpIrq=1;
static volatile unsigned int g_uiGpioLongkeyTicks;
static unsigned int g_uiSdDetInited=0;
static unsigned int g_uiIsCustomed=0;
static unsigned int g_uiButtonInited_Jxd=0;

//Button_t g_stGpioButtons ;
//Button_t g_stGpioButtons2;

static SensorOps_st g_pastPictDev638[NUMBER_PICTURE_DEVISE_GPIO];

static ProductModel_st g_stJxd638;

/*****************************************************************************************************
                                          函数声明
*****************************************************************************************************/

static int initPictureDevOps_638(SensorOps_st *pstPictDev);
static int initBDISP_638(void);
static int initGpioButton_638(void);
static int initHeadPhone_GPIO_Jxd638(void);
static int initSDDetect_Jxd638(void);
static int initHoldKey_GPIO_Jxd638(void);
static int initCustom_GPIO_Jxd638(void);
int init_Jxd638(void);

static void gpio0Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg);
static void gpio1Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg);

static void sdDetect_dsr_Jxd638(void);
static void holdkey_dsr_Jxd638(void);
static void HpDetect_dsr_Jxd638(void);

static void longkeyNotify_Jxd638(Button_t *pstBt0,  Button_t *pstBt1);

static void keyscanGp0_dsr_Jxd638( KeyPostProc pfPostMsg);
static void keyscanGp1_dsr_Jxd638( KeyPostProc pfPostMsg);

static void getButton_Jxd638(int group, Button_t **pstData);
static void getPictdev_Jxd638(SensorOps_st **pstData);

static int isSDPlugIn_Jxd638(void );

int setSpkmute_SAR_JxdComm(int val);

int PostProc(unsigned int aScanCode, unsigned int stamp);

/*****************************************************************************************************
                                          函数定义
*****************************************************************************************************/

static void gpio0Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg)
{
    if (pendIrq & SDDETECT_MASK_SHIFT_BIT_BODY)
    {
        sdDetect_dsr_Jxd638();
    }
    if (pendIrq & SCANEKY_MASK_GPIO_BODY)
    {
        keyscanGp0_dsr_Jxd638(pfPostMsg);
    }               

    if (pendIrq & HPHONE_MASK_SHIFT_BIT_BODY)
    {
        HpDetect_dsr_Jxd638();
    }
   
    if (pendIrq & HOLDKEY_MASK_SHIFT_BIT_BODY)
    {
        holdkey_dsr_Jxd638();
    }   

}

//============================================================================================

static void gpio1Irq_dsr_Jxd638(unsigned int pendIrq, KeyPostProc pfPostMsg)
{
    if (pendIrq & SCANEKY_MASK_GPIO2_BODY)
    {
        keyscanGp1_dsr_Jxd638(pfPostMsg);
    }
}

//============================================================================================

static int initPictureDevOps_638(SensorOps_st *pstPictDev){return 0;}
static int initBDISP_638(void){return 0;}
static int initGpioButton_638(void){return 0;}
static int initSDDetect_Jxd638(void){return 0;}
static int initHoldKey_GPIO_Jxd638(void){return 0;}
static int initHeadPhone_GPIO_Jxd638(void){return 0;}
static int initCustom_GPIO_Jxd638(void){return 0;}

static void sdDetect_dsr_Jxd638(void){;}
static void HpDetect_dsr_Jxd638(void){;}

static void keyscanGp0_dsr_Jxd638( KeyPostProc pfPostMsg){;}
static void keyscanGp1_dsr_Jxd638( KeyPostProc pfPostMsg){;}

static void longkeyNotify_Jxd638(Button_t *pstBt0,  Button_t *pstBt1){;}

static void getButton_Jxd638(int group, Button_t **pstData){;}
static void getPictdev_Jxd638(SensorOps_st **pstData){;}

static void holdkey_dsr_Jxd638(void){;}

static int isSDPlugIn_Jxd638(void ){return 0;}

int setSpkmute_SAR_JxdComm(int val){return 0;}

int PostProc(unsigned int aScanCode, unsigned int stamp){return 0;}

//=============================================================================================

int init_Jxd638(void)
{
    if(g_uiIsCustomed)
    {   
        cout<<"init_Jxd638() already init \n";
        return 1;
    }

    //g_uiGpioLongkeyTicks =LONGKEY_MINOR_ADJUST_TICKS;
   
    initBDISP_638();
    initGpioButton_638();
    //initHeadPhone_GPIO_Jxd638();
    //initSDDetect_Jxd638();
    initHoldKey_GPIO_Jxd638();
    //initCustom_GPIO_Jxd638();
    initPictureDevOps_638(g_pastPictDev638);
        
    cout<<"initCustom_Jxd638() OK \n";   

    g_uiIsCustomed++;

    return 0;
}
/*****************************************************************************************************
                                          主函数定义
*****************************************************************************************************/

int main(void)
{
    int ret;

        ProductModel_st g_stJxd638={
                                        initCustom_GPIO_Jxd638,   
                                        initSDDetect_Jxd638,
                                        isSDPlugIn_Jxd638,
                                        setSpkmute_SAR_JxdComm,
                                        getPictdev_Jxd638,
                                        getButton_Jxd638,
                                        gpio0Irq_dsr_Jxd638,   
                                        gpio1Irq_dsr_Jxd638,
                                        longkeyNotify_Jxd638,
                                        initHeadPhone_GPIO_Jxd638,
                                        "Jxd 638"
                                    };

    ret=init_Jxd638();
    return ret;
}
编译通过了,连接的时候发生如下错误:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Linking...
strcut.obj : error LNK2005: "int __cdecl init_Jxd638(void)" (?init_Jxd638@@YAHXZ) already defined in Cpp1.obj
strcut.obj : error LNK2005: _main already defined in Cpp1.obj
Debug/Cpp1.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.

Cpp1.exe - 1 error(s), 0 warning(s)

再次请明白人指教?
2010-05-20 12:01
liangxiao
Rank: 2
等 级:论坛游民
帖 子:7
专家分:11
注 册:2010-4-2
收藏
得分:3 
你好像重定义了
2010-05-20 12:03
wjk_0713
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-5-19
收藏
得分:0 
能详细说说嘛?
2010-05-20 12:04
yc2575757
Rank: 7Rank: 7Rank: 7
来 自:北京
等 级:黑侠
威 望:1
帖 子:113
专家分:522
注 册:2010-5-7
收藏
得分:7 
vc6.0下无错误,跑出来的结果为initCustom_Jxd638<> OK
2010-05-20 15:16
wjk_0713
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-5-19
收藏
得分:0 
不是吧,那我的错误哪儿来的。难道我装的VC有问题。
2010-05-21 14:43
wjk_0713
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-5-19
收藏
得分:0 
找到原因了,建了2个源文件,编译生成的odj文件在一起,所以连接的时候,两个矛盾了。谢谢各位的指教!
2010-05-21 14:52
快速回复:C语言程序出现下面的错误“syntax error”,原因不明,请指教?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060376 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved