MQX 4.2.0 _io_write vs const data

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MQX 4.2.0 _io_write vs const data

跳至解决方案
2,238 次查看
rvigneault
Contributor III

Hi,

We are using MQX 4.2.0 and I was quite surprised that _io_write is defined to take a non-const buffer for the data:

extern _mqx_int    _io_write(MQX_FILE_PTR, void *, _mqx_int);

I would have expected the second parameter to be something like const void*, furthermore that it is used in the inline definition of fwrite:

#define  fwrite(ptr,so,no,f) (_io_write(f,ptr,(so)*(no))/(so))

My question is: is it safe to assume that neither fwrite nor _io_write will modify the pointer that is given to them?

Can there be a problem to remove the const (using a cast) of an array we want to write using fwrite?

Thanks!

标记 (4)
1 解答
2,119 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Ruby:

Thank you for your feedback. Yes, this is an issue. and it is fixed in MQX v5. 

Your can fixed it by yourself.

 For MQX v5 we did a full clean up of the code and we made things more consitent and up to date.

Regards

Daniel

在原帖中查看解决方案

3 回复数
2,120 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Ruby:

Thank you for your feedback. Yes, this is an issue. and it is fixed in MQX v5. 

Your can fixed it by yourself.

 For MQX v5 we did a full clean up of the code and we made things more consitent and up to date.

Regards

Daniel

2,119 次查看
rvigneault
Contributor III

Hi Daniel,

Thank you for your answer.

Just to be clear, the issue here is only that the parameter is not declared as const?

I mean, it is used as const (i.e. not modified) by the _io_write implementation right?

If so, I guess that _strnlen is the same (i.e. the first parameter is not modified and can be considered as const char*). I stumbled upon it yesterday after my question.

Thanks!

0 项奖励
回复
2,119 次查看
danielchen
NXP TechSupport
NXP TechSupport

Yes, you are right.

Regards

Daniel