You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handling of preprocessor-defined strings in TRICE macro #293
I found this situation while adapting my old printf source code to Trice. Here there are useful information on how to handle strings.
I've just found another situation where a constant string is defined through a preoprocessor macro.
As an example #define VERSION_STRING "1.0.0"
How should this be handled?
I tried with TRICE("The version is:"VERSION_STRING);
but trice tool receives the message The version is VERSION_STRING
and I think the reason is that as reported ion the User Guide,
string concatenation within TRICE macros is untested and expected not to work. The reason lays inside the way the update tool works (right now)
Which is the optimal way to handle this kind of strings (known at compile time) at the moment?
Thanks
In a long term roadmap, this could be an improvement of the update feature of the trice tool.
I would expect not working at all or The version is:VERSION_STRING in the given example. You can also have a look into the til.json. My recommendation:
#defineMAJOR 1
#defineMINOR 0
#definePATCH 0
TRICE8( "The version is: %d.%d.%d\n");
The **trice ** tool cannot perform, what a preprocessor does. It is limited to simple string replacements. If you really need such string concatenation, you could try a 2nd trice update run on the preprocessor output. But I think it is not worth the effort and brings in difficulties with the ID handling. What about this:
#defineDUMMY_STRING "The string is dummy string"
TRICE( DUMMY_STRING );
Then, before running trice u, use a text processor to replace DUMMY_STRING.
I cannot imagine the need for that. Would you please tell me more about the use case?
@rokath I agree with you. trice tool cannot do the job of a C preprocessor, and the proposed workaround it's not worth the effort.
This topic comes from a real job of replacing printf code into trice code.
Sometimes in C it's quite common using some #define to create compile-time-known items (strings, numbers, ...)
Usually they're kept into a .h file that can be changed to reconfigure the project with other parameters.
All this data is know at compile time (after preprocessing task, in reality) and so they could be optimized with trice.
But the effort is too high and it goes beyond the scope of trice tool.
I think that the best solution is to use them like dynamic strings or data (subotimal way, but we can live with it):
#defineDUMMY_STRING "The string is dummy string"
#defineMAGIC_NUMBER 3
...
TRICE_S( "msg:%s\n", DUMMY_STRING);
TRICE( "msg:The value of the magic number is %d\n", MAGIC_NUMBER);
Activity
rokath commentedon May 27, 2022
I would expect not working at all or
The version is:VERSION_STRINGin the given example. You can also have a look into the til.json. My recommendation:escherstair commentedon May 27, 2022
In this case the workaround is ok, but imagine it's
The C preprocessor can concatenate the strings in this way
but I understand that trice tool (at the moment) doesn't play the role of the preprocessor.
And so
doesn't concatenate the string.
rokath commentedon May 27, 2022
The **trice ** tool cannot perform, what a preprocessor does. It is limited to simple string replacements. If you really need such string concatenation, you could try a 2nd
trice updaterun on the preprocessor output. But I think it is not worth the effort and brings in difficulties with the ID handling. What about this:Then, before running
trice u, use a text processor to replace DUMMY_STRING.I cannot imagine the need for that. Would you please tell me more about the use case?
escherstair commentedon May 30, 2022
@rokath I agree with you.
trice tool cannot do the job of a C preprocessor, and the proposed workaround it's not worth the effort.
This topic comes from a real job of replacing printf code into trice code.
Sometimes in C it's quite common using some
#defineto create compile-time-known items (strings, numbers, ...)Usually they're kept into a .h file that can be changed to reconfigure the project with other parameters.
All this data is know at compile time (after preprocessing task, in reality) and so they could be optimized with trice.
But the effort is too high and it goes beyond the scope of trice tool.
I think that the best solution is to use them like dynamic strings or data (subotimal way, but we can live with it):
rokath commentedon Jun 1, 2022
Maybe you can write inside your header file
and in your C-file
This could work but may cause difficulties with the location information what probably is solvable.