MQX 4.2.0 _io_write vs const data

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX 4.2.0 _io_write vs const data

Jump to solution
1,276 Views
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!

1 Solution
1,157 Views
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

View solution in original post

3 Replies
1,158 Views
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,157 Views
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 Kudos
1,157 Views
danielchen
NXP TechSupport
NXP TechSupport

Yes, you are right.

Regards

Daniel