Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

__FILE__ doesn't contain path in VC7 ?

18 views
Skip to first unread message

Karl Lehmann

unread,
Jul 30, 2002, 9:04:43 AM7/30/02
to
The following program behaves differently in VC6 and VC7:

------ FileTest.cpp ------
#include <stdio.h>

void main()
{
printf("The current file is: %s\n", __FILE__);
}
--------------------------

In VC6 (SP5), this prints the full path of the current source file,
e.g.:

The current file is: d:\code\test\filetest\filetest.cpp


However, in VC7, I only get the name of the source file, but not the
path:

The current file is: FileTest.cpp


Hence it seems that the preprocessor has changed the behavior of
__FILE__ from VC6 to VC7. Does anyone know how to get the full path in
VC7? Any help would be greatly appreciated.

Karl Lehmann

Victor Bazarov

unread,
Jul 30, 2002, 9:14:07 AM7/30/02
to
"Karl Lehmann" <yogb...@hotmail.com> wrote...
> [...] Does anyone know how to get the full path in

> VC7? Any help would be greatly appreciated.


I don't have VC7, but the first place I'd look would be TFM (you
know, as in "RTFM"...) Search the MSDN for "predefined macros".

Victor
--
Please remove capital A's from my address when replying by mail


Walter Briscoe

unread,
Jul 30, 2002, 10:36:32 AM7/30/02
to
In article <5a65b02b.02073...@posting.google.com> of Tue, 30
Jul 2002 06:04:43 in microsoft.public.vc.language, Karl Lehmann
<yogb...@hotmail.com> writes

Your pointing at the preprocessor. I think you should look at the IDE.

The following uses VC6 and the command line.

C:\WINDOWS\TEMP> type FILE.cpp
char *d = __FILE__;

C:\WINDOWS\TEMP> cl file.cpp /P /C /c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

file.cpp

C:\WINDOWS\TEMP> type file.i
#line 1 "file.cpp"
char *d = "file.cpp";

C:\WINDOWS\TEMP> cl C:\WINDOWS\TEMP\file.cpp /P /C /c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

file.cpp

C:\WINDOWS\TEMP> type file.i
#line 1 "C:\\WINDOWS\\TEMP\\file.cpp"
char *d = "C:\\WINDOWS\\TEMP\\file.cpp";

C:\WINDOWS\TEMP>

--
Walter Briscoe

Doug Harrison [MVP]

unread,
Jul 30, 2002, 2:50:54 PM7/30/02
to
Karl Lehmann wrote:

>The following program behaves differently in VC6 and VC7:
>
>------ FileTest.cpp ------
>#include <stdio.h>
>
>void main()
>{
> printf("The current file is: %s\n", __FILE__);
>}
>--------------------------
>
>In VC6 (SP5), this prints the full path of the current source file,
>e.g.:
>
>The current file is: d:\code\test\filetest\filetest.cpp
>
>
>However, in VC7, I only get the name of the source file, but not the
>path:
>
>The current file is: FileTest.cpp

Both VC6 and VC7 print the same bare filename for me. The differences
become apparent when __FILE__ is expanded within a #included file.

>Hence it seems that the preprocessor has changed the behavior of
>__FILE__ from VC6 to VC7. Does anyone know how to get the full path in
>VC7? Any help would be greatly appreciated.

There are some bugs in this area. For example, see this thread:

http://groups.google.com/groups?threadm=31f001c1b4bb%241cb34800%24a4e62ecf%40tkmsftngxa06


--
Doug Harrison
Microsoft MVP - Visual C++
Eluent Software, LLC
http://www.eluent.com
Tools for VC++, VS.NET, and Windows

0 new messages