some const std::strings appear to be corrupted.
hi, I'm facing a somewhat weird problem, any ideas on how to debug it would be most welcome.
the bottom line : in a class's destructor , some (not all ) std::cout<< const std::string generates corrupted output :
std::string TempMsg;
const std::string dummy = "dummy";
TempMsg = "dummy " + dummy;
std::cout << TempMsg << std::endl;
--works. (for local definition of const string) :-)
TempMsg = " FfrMsgStateOK " + FfrMsgStateOK;
WriteInfoToLog(TempMsg);
std::cout << TempMsg << std::endl;
-- FfrMsgStateOK is define in somefile.hpp as const std::string FfrMsgStateOK = "OK"; works.
while
TempMsg = "FfrMsgNodeStateReplayOk" + FfrMsgNodeStateReplayOk ;
WriteInfoToLog(TempMsg);
std::cout << TempMsg << std::endl;
writes the following garbeld/ corrupted output : FfrMsgNodeStateReplayOk j�tate,Rea` and not the desired "FfrMsgNodeStateReplayOk FfrMsgNodeStateReplayOk".
FfrMsgNodeStateReplayOk is fefined in the same somefile.hpp (as const std::string FfrMsgNodeStateReplayOk = "NodeNewState,Ready";) , its actually the following definition after FfrMsgStateOK
this seems to be ros related,
since the same code but without an additional "layer" ( ros listener ) , works without any issues.
(
my application has several layers
at the lowest level there are several header files with constants and classes to be used by the following layers .
the code in question works fine up to the one before last layer.
the last layer is a ros listener...and when executing this executable the corruption occurs ).
it seems to me like some sort of linkage error.
i understand that I have not ruled out a runtime memory corruption by the code in the last layer.
( but i dont realy have a clue on how to check/prove this )
( at runtime i basically start the node, read a few parameters , and stop the node, as i've written the messages are printed in one of the layers destructors)
this is occurring on both ubuntu 16 and ubuntu 20. ( and corresponding ros versions ) gcc 8.4.0 tried building both with catkin and without ( same results )
please help :-) Omer.