Hi,
I am trying to change the default CPP behavior of rtiddsgen for:
file.idl: const string str_name = "my string";
The default is to create the following code in the header file:
file.h: static const DDS_Char * str_name= "my string";
But this creates a new static string in every object the header file is included and also gives warnings in every object that it's not used.
The way it should be done, is to create a single const string in the body with a corresponding extern statement in the header so there is only a single instance of the string within the executable.
file.cpp: const DDS_Char * str_name= "my string";
file.h: extern const DDS_Char * str_name;
I read in the Code Generator manual that the rtiddsgen templates can be modified to accomplish this. So I modified typeBody.vm and typeHeader.vm in the resource/app/app_support/rtiddsgen/templates/cpp03 directory but when I run rtiddsgen, it doesn't seem to use my modified .vm files. Is there something I'm missing?
Any help would be appreciated.
Thanks,
Chris
I should add that I'm using RTI DDS Ver 5.2.3
Hi Chris,
It is a known issue, with ID CODEGENII-873, you will see it in the following release.
You are correct, const string is not generated correctly.
According to the OMG specification "C++ Language Mapping" the mapping of "const string" from IDL to C++ should be:
In the case that you want to modify the template in the meantime. You will have to do the following changes in resource/app/app_support/rtiddsgen/templates/c/typeMacros.vm:
Please let me know if it works for you.
Best,
Antonio
Hi Antonio,
I made the change you suggested but unfortunately it doesn't fix the warning issue, and I didn't expect it to.
However, by changing "static" to "extern" in the typeMacros.vm file and removing the =$() part, I got half of my fix, meaning the header now has what I want.
File.h: extern const DDS_Char * str_name;
Now I just need a way to add the corresponding declaration to the body (file.cpp) so that it contains the following line:
File.cpp: const DDS_Char * str_name= "my string";
Can you help me with this?
Thanks,
Chris