令牌预期前pression

令牌预期前pression

本文介绍了前“{”令牌预期前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:之前的预期前pression{标记为我以前评论过就行了。如果结构已经被定义它为什么会需要一个{之前令牌。感谢您的帮助,您可以提供。

 结构sdram_timing {
    U32 wrdtr;
    U32 clktr;
};INT校准(无效);
unsigned char型read_i2c_cal(无效);
静态unsigned int类型eepcal [15];主(){
    DQS_autocalibration();
}INT校准(无效)
{
    结构sdram_timing scan_list [30];    read_i2c_cal();
    如果(eepcal [0] == 0){       scan_list = {{eepcal [1],eepcal [2]},{-1,-1}}; //< - 问题LINE        }
        其他{
            //富
        }    返回0;
}unsigned char型read_i2c_cal(无效){
    eepcal [0] = 0;
    eepcal [1] = 02;
    eepcal [2] = 03;
}


解决方案

这个错误是因为你不能将数组分配的方式,即只能进行初始化。

  INT ARR [4] = {0}; //这个工程
INT ARR2 [4];ARR2 = {0}; //这不并会导致错误ARR2 [0] = 0; // 没关系
memset的(ARR2,0,4 *的sizeof(int)的); //就是太

所以,应用此您具体的例子:

 结构sdram_timing scan_list [30];
scan_list [0] .wrdtr = 0;
scan_list [0] .clktr = 0;

或者你可以使用memset的同样的方式,但不是的sizeof(int)的您需要的结构大小。这并不总是工作...但鉴于你的结构,它会的。

I am getting: "error: expected expression before '{' token" for the line I've commented before. If the struct is already defined why would it need a "{" before token. Thanks for any help you can provide.

struct sdram_timing {
    u32 wrdtr;
    u32 clktr;
};

int calibration(void);
unsigned char read_i2c_cal(void);
static unsigned int eepcal[15];

main() {
    DQS_autocalibration();
}

int calibration(void)
{
    struct sdram_timing scan_list[30];

    read_i2c_cal();
    if(eepcal[0] == 0){

       scan_list = {{eepcal[1], eepcal[2]}, {-1, -1}}; // <-- PROBLEM LINE

        }
        else {
            //foo
        }

    return 0;
}

unsigned char read_i2c_cal(void) {
    eepcal[0] = 0;
    eepcal[1] = 02;
    eepcal[2] = 03;
}
解决方案

The error is because you can't assign an array that way, that only works to initialize it.

int arr[4] = {0}; // this works
int arr2[4];

arr2 = {0};// this doesn't and will cause an error

arr2[0] = 0; // that's OK
memset(arr2, 0, 4*sizeof(int)); // that is too

So applying this to your specific example:

struct sdram_timing scan_list[30];
scan_list[0].wrdtr = 0;
scan_list[0].clktr = 0;

or you could use memset the same way, but instead of sizeof(int) you need size of your structure. That doesn't always work... but given your structure, it will.

这篇关于前“{”令牌预期前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:41