PROBLEM
I need a way to generate unique values using a preprocessor directive. The aim is that each time the macro is called, it will have a unique integral identifier. But it should retain it's value across files. Kind of like a preprocessor counter for the number of times a call is made to the function.
FURTHER INFO
The macro I am using is:
#define LOG_MSG(a) log_msg(?)
- 'a' is a string that the user wants to print.
- log_msg is a custom function used to print a message on the UART
- The '?' if the part I need help with.
This macro would be defined at a single place only. During the preprocessing stage, the '?' would be replaced by a unique identifier. We are doing this to reduce the overhead that comes with strings as this code will run on an embedded device. After the preprocessing the identifiers and the related strings would be extracted and a table would be created that would map them (this would be on the application side).
Since this will be used across multiple files, I wanted a way to generate a unique identifier (integral not string) for every use across the multiple files(an identifier for every unique string would be ideal but not necessary).
Any ideas?
Please do mention if there is any missing or incomplete information
Notes
__COUNTER__
was the first thing I tried, but it doesn't hold across files.
__FILE__
would give me a string which defeats the purpose.
Some people mentioned using unique file identifiers. But I don't want to statically allocate these. We are using CCS(it's built on Eclipse Kepler) to build this code. So I was thinking that we could add something to the build system to do what @embedded_guy mentioned. Anyone know how to that?
Thanks