'__FILE__" Expansion should not include the path

cancel
Showing results for 
Search instead for 
Did you mean: 

'__FILE__" Expansion should not include the path

6,882 Views
davekellogg
Contributor II

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?

Labels (1)
Tags (1)
5 Replies

1,258 Views
davekellogg
Contributor II

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.

0 Kudos

1,062 Views
ErichS
Senior Contributor IV

@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

0 Kudos

1,258 Views
J2MEJediMaster
Specialist I

To ensure that your feature request gets recognized and looked at, you need to file a Service Request on that. Click here to file a service request.

 

---Tom

0 Kudos

1,258 Views
CrasyCat
Specialist III

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):

 

"

__FILE__
This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in #include or as the input file name argument. For example, "/usr/local/include/myheader.h" is a possible expansion of this macro."

 

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

0 Kudos

1,258 Views
Lundin
Senior Contributor IV
ISO C specifies __FILE__ as (ISO 9899:1999 6.10.8): "The presumed name of the current source file"

Whether that includes the full path or not clear. There is however certainly nothing in the C standard enforcing a full path.

0 Kudos