expected expression before '{' token

后端 未结 4 1844
清歌不尽
清歌不尽 2021-01-04 17:02

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.

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 17:45

    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.

提交回复
热议问题