Justin Richards
2017-12-01 11:46:09 UTC
I have a re-usable source file that is used in many projects that is used
to generate some information about the environment that it was built in.
I use existing predefined or generated constants (not sure what to call
them) like
__DATE__
__TIME__
__FILE__
All is good until I tried to use __FILE__. As per the description __FILE__
returns the path and file name of the file that actually contains the
__FILE__ directive. Not what I want.
I want the actual file name of the parent source file as it is more
meaningful.
Thinking I was on to a solution I did this
#define __PROJECT_PATH_FN__ __FILE__
then use __PROJECT_PATH_FN__ in the in re-usable source file but the
pre-processor does what it does and replaces _PROJECT_PATH_FN__ with
__FILE__.
I was hoping it (the pre-compiler) would expand __FILE__ when it first
encounters it but sadly no.
I have a solution but it requires the target processor to do some of the
work like this
const char __PROJECT_PATH_FN__[] = __FILE__;
Then I can use __PROJECT_PATH_FN__ where needed and it expands out to the
PATH and FILENAME of the parent source file.
I assume "const char" allocates program space to store the string.
This is OK, but if anyone knows a better way i would be curious how I go
about it.
I tried understanding #pragma, thinking this may help but I dont understand
it purpose.
Any thoughts?
Cheers Justin
to generate some information about the environment that it was built in.
I use existing predefined or generated constants (not sure what to call
them) like
__DATE__
__TIME__
__FILE__
All is good until I tried to use __FILE__. As per the description __FILE__
returns the path and file name of the file that actually contains the
__FILE__ directive. Not what I want.
I want the actual file name of the parent source file as it is more
meaningful.
Thinking I was on to a solution I did this
#define __PROJECT_PATH_FN__ __FILE__
then use __PROJECT_PATH_FN__ in the in re-usable source file but the
pre-processor does what it does and replaces _PROJECT_PATH_FN__ with
__FILE__.
I was hoping it (the pre-compiler) would expand __FILE__ when it first
encounters it but sadly no.
I have a solution but it requires the target processor to do some of the
work like this
const char __PROJECT_PATH_FN__[] = __FILE__;
Then I can use __PROJECT_PATH_FN__ where needed and it expands out to the
PATH and FILENAME of the parent source file.
I assume "const char" allocates program space to store the string.
This is OK, but if anyone knows a better way i would be curious how I go
about it.
I tried understanding #pragma, thinking this may help but I dont understand
it purpose.
Any thoughts?
Cheers Justin
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist