MQX 4.2.0 _io_write vs const data

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MQX 4.2.0 _io_write vs const data

ソリューションへジャンプ
1,565件の閲覧回数
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 解決策
1,446件の閲覧回数
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 返答(返信)
1,447件の閲覧回数
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

1,446件の閲覧回数
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 件の賞賛
返信
1,446件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Yes, you are right.

Regards

Daniel