C中的类型转换错误

时间:2015-02-25 19:39:52

标签: c

873: error: invalid conversion from 'void*' to 'fabl_infod_twamp_reply_t*'

第870-873行的代码是;

     870:        reply_hdr = 
     871:              fabl_infod_extract_from_message(sizeof(fabl_infod_twamp_reply_t), 
     872:                                   &buffer_pos,
     873:                                   &buffer_length);

“fabl_infod_extract_from_message”的函数参数;

static inline void * fabl_infod_extract_from_message (uint32_t struct_size, 
                                  uint8_t **buffer_pos, 
                                  uint32_t *buffer_length)

任何建议都赞赏!

虽然我曾尝试过将其指定为;

reply_hdr =  (void *)fabl_infod_extract_from_message(sizeof(fabl_infod_twamp_reply_t), 
                                        &buffer_pos,
                                        &buffer_length); 

1 个答案:

答案 0 :(得分:3)

void*投射到void*的影响非常小。

如果fabl_infod_extract_from_message的实际返回值(即void*的“后面”)是fabl_infod_twamp_reply_t*,则应将其转换为该类型:

reply_hdr = (fabl_infod_twamp_reply_t*) fabl_infod_extract_from_message ...

或者,使用C ++风格的演员:

reply_hdr = static_cast<fabl_infod_twamp_reply_t*>(fabl_infod_extract_from_message...