www.digitalmars.com         C & C++   DMDScript  

c++ - __FILE__ macro

reply Karyn Chen <Karyn_member pathlink.com> writes:
I am using the __FILE__ macro but am having problems. Sometimes the macro is
replaced by the file name, File.cc, both other times it is replaced by the whole
path name like /home/dev/test/File.cc. How can I prevent the whole path name
from printing?
Nov 15 2004
parent Scott Michel <scottm aero.org> writes:
Karyn Chen wrote:
 I am using the __FILE__ macro but am having problems. Sometimes the macro is
 replaced by the file name, File.cc, both other times it is replaced by the
whole
 path name like /home/dev/test/File.cc. How can I prevent the whole path name
 from printing?

It depends on the file name passed to the compiler. If the command line contains "File.cc", then __FILE__ will be "File.cc". OTOH, if you pass a path on the command line, the path version is what you get. Search google for a function called "basename".
Nov 15 2004