Handling of preprocessor-defined strings in TRICE macro #318
Replies: 6 comments
-
I would expect not working at all or #define MAJOR 1
#define MINOR 0
#define PATCH 0
TRICE8( "The version is: %d.%d.%d\n"); |
Beta Was this translation helpful? Give feedback.
-
In this case the workaround is ok, but imagine it's #define DUMMY_STRING "this is a dummy string" The C preprocessor can concatenate the strings in this way printf("The string is:"DUMMY_STRING); but I understand that trice tool (at the moment) doesn't play the role of the preprocessor. TRICE("The string is:"DUMMY_STRING); doesn't concatenate the string. |
Beta Was this translation helpful? Give feedback.
-
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 #define DUMMY_STRING "The string is dummy string"
TRICE( DUMMY_STRING ); Then, before running I cannot imagine the need for that. Would you please tell me more about the use case? |
Beta Was this translation helpful? Give feedback.
-
@rokath I agree with you. This topic comes from a real job of replacing printf code into trice code. #define DUMMY_STRING "The string is dummy string"
#define MAGIC_NUMBER 3
...
TRICE_S( "msg:%s\n", DUMMY_STRING);
TRICE( "msg:The value of the magic number is %d\n", MAGIC_NUMBER); |
Beta Was this translation helpful? Give feedback.
-
Maybe you can write inside your header file #include "trice.h"
#define DUMMY_STRING TRICE( "msg:The string is dummy string\n"); and in your C-file
This could work but may cause difficulties with the location information what probably is solvable. |
Beta Was this translation helpful? Give feedback.
-
Pleas read https://github.com/rokath/trice/blob/master/docs/TriceUserGuide.md#97-dynamic-stringsbuffers-only-as-variable-inside-trice-macros-before-v0610 - now you can write |
Beta Was this translation helpful? Give feedback.
-
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,
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.
Beta Was this translation helpful? Give feedback.
All reactions