I'm using CodeWarrior v5.0 for the S12X, on Windows XP.
I use the predefined "__FILE__" macro to build an ASSERT macro of my own.
The problem is that __FILE__ is replaced by the file name ***plus the file's entire path***. This means that if I build my project in two different directories, I will have different load images (because the text contains the path). This causes a lot of difficulty when different team members rebuild in different working directories, and get differing load images from the same exact source files.
Has anyone discovered a way to suppress the path in the __FILE__ macro, so it expands to only the file name and extension?
I did some further googling, and found these points of interest. Evidently, some versions of CW do (or once did) have a proagma "fullpath_file" for controlling how __FILE__ expands.
Who at FreeScale should I contact for a feature change request to get this pragma into CodeWarrior for HCS12(X)?
+++++++++++++++++
http://www.freescale.com/files/soft_dev_tools/doc/ref_manual/CCOMPILERRM.pdf
CodeWarrior Development Tools C Compilers Reference 3.2 (Dated 2004 July 06), page 153
Pragma: fullpath_file - Controls if __FILE__ macro returns a full path or the base filename.
Syntax: #pragma fullpath_file on | off | reset
Targets: All platforms.
Remarks: When on, the __FILE__ macro returns a full path to the current file, otherwise it returns the base filename.
++++++++++++++++++++++
http://www.freescale.com/files/soft_dev_tools/doc/ref_manual/ColdFire_Build_Tools_Reference.pdf
CodeWarrior Development Studio ColdFire Architectures Edition Build Tools Reference pg 308 (Revised 11 July 2006)
Pragma: fullpath_file - Controls if __FILE__ macro returns a full path or the base filename.
Syntax: #pragma fullpath_file on | off | reset
Targets: All platforms.
Remarks: When on, the __FILE__ macro returns a full path to the current file, otherwise it returns the base filename.
+++++++++++++++++++++++
http://lists.apple.com/archives/Xcode-users/2005/Mar/msg00117.html
>Is it possible to get gcc to output just the source file name for __FILE__, without the entire absolute path?
>e.g. "foo.c" instead of "Users/somebody/project/source/subfolder/ foo.c"?
Comparing some large source trees built with both Codewarrior and gcc, it looks like CW does this, but I don't see any flag to make gcc do it...
GCC uses the path you give it. So if you tell it to compile foo.c, __FILE__ will be foo.c, but if you tell it to compile /Users/somebody/ foo.c, __FILE__ will be /Users/somebody/foo.c.
@davekellogg, @J2MEJediMaster , @Lundin , @CrasyCat
I know this is an old thread, but I wrote an article about how to tweak the __FILE__ macro on gcc not to include the path:
assert(), __FILE__, Path and other cool GNU gcc Tricks to be aware of
I hope this helps,
Erich
Hello
According to definition, __FILE__ returns the full path to the source file.
Extract from Standard Predefined macro definition by GNU (http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/Standard-Predefined-Macros.html):
"
If you need to remove the paths and keep only base file name, you need to get the file name in a string and format the string as you want to see it.
CrasyCat