[openamq-dev] Should parameters in WireAPI should be const when possible ?

Martin Sustrik sustrik at imatix.com
Tue Dec 18 10:22:18 CET 2007


Hi,

> Using the WireAPI functions 
> 
> amq_content_basic_set_body
> amq_content_basic_set_message_id
> amq_client_session_basic_publish
> 
> is problematic due to the prototypes not declaring the byte* data parameter 'const'.
> There can be no reason for the WireAPI to modify the passed in "byte *data", 
> and good programming discipline dictates that these parameters should be const when appropriate.

Yes, you are right. OpenAMQ is written entirely without const modifiers. 
This is not a good programming technique, however, I've tried to add 
consts once, but after some investigation I've found out that it would 
mean to modify almost all the generic code generators (supplying 
additional parameters to code generating process) so I've gave up.

> I understand fixing this *may* break legacy applications.

Yes. The existing interfaces shoudn't be changed to maintain backward 
compatibility. Rather, new interfaces should be added.

> I am willing to supply a patch for this, but am opening a discussion beforehand.
> 
> Comments welcome.

What you should do IMO is to create a wrapper header file, that would 
wrap existing functions adding const modifiers where neccessary and 
forward the calls to the existing interface casting the consts to 
non-consts.

Martin


More information about the openamq-dev mailing list