错误:#137:表达式必须是可修改的左值

时间:2016-05-26 09:12:15

标签: c

我读了关于这个主题的所有问题,但没有一个问题似乎像我的。但是,我收到错误:表达式必须是可修改的左值。下面列出了建立错误的C代码的一部分。

 ws->fetch_next_state = &deg1_user_init;        
 ws->back_to_current  = &text_frame_print; 
 ws->_frame.text_buff[0] = deg_symbol_th; // error line
 ws->_frame.text_buff[1] = deg_symbol_te; //error line
 ws->_frame.object_no = 2;                                  
 ws->objects_counter = 0;`

上层代码snipet的意思是将常量内存区域的指针传递给将字符发送到外围设备的例程。

对象deg_symbol_thdeg_symbol_te定义为

 char deg[2] = {0xF8, 0x00}; 
 const struct text_object deg_symbol_th = {6,3,2,45,240, deg};
 const struct text_object deg_symbol_te = {6,10,2,265,240, deg};
 const struct text_object deg_symb_svc =  {6,3,2,430,35, deg};

ws->_frame.text_buff[0]是结构的一部分

struct frame
{
enum frame_sta frame_status;
enum frame_sta frame_status_diff;
const struct text_object *text_buff;
const struct box_object  *box_buff;
const struct area_object *area_buff;
uint8_t object_no;
};


struct wspace{
   struct netimer       period;
   struct nequeue   deferred;
   struct nevent *  deferred_queue_storage[EPA_EEPROM_QUEUE_SIZE];
   struct nepa *    producer;
   struct event_i2c_transfer        transfer;
   struct text_object   *Val_frame_buffer[15];
   struct frame        _frame;
   naction      (*back_to_current)(struct nsm * sm, const struct nevent * event); 
   naction      (*fetch_next_state)(struct nsm * sm, const struct nevent * event);           
   uint32_t     i2c_retry;
   uint8_t      i2c_buffer[35];
}ws;

可能是什么问题?

1 个答案:

答案 0 :(得分:2)

成员next_buff是指向const数据的指针,这意味着即使您可以更改next_buff指针本身的值,也无法更改结构的内容(s )它指向。因此,要解决此问题,请移除声明const中的const struct text_object *text_buff