且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

前“{”令牌预期前pression

更新时间:2022-12-30 18:18:37

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

  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.