Community
cancel
Showing results for 
Search instead for 
Did you mean: 
SergeyKostrov
Valued Contributor II
86 Views

How could I control the format of a macro __FILE__?

The name of the current source file is stored by a C/C++ compiler in ANSI-Compliant Predefined macro __FILE__.

How could I control the format? For example:

MinGW stores it as: ../../folder3/test.cpp

Visual C++ compiler stores it as: c:\\folder1\\folder2\\folder3\\test.cpp

0 Kudos
3 Replies
Georg_Z_Intel
Employee
86 Views

Hello Sergey,

AFAIK the way the __FILE__ macro is formatted depends on how you provide the source file names to the compiler, e.g:

file.c:
[cpp]#include 

int main(int argc, char **argv)
{
    printf("%sn", __FILE__);
    return 0;
}[/cpp]

[bash]C:temp> icl file.c
C:temp> file.exe
file.c[/bash]
or
[bash]C:temp> icl C:tempfile.c
C:temp> file.exe
C:tempfile.c[/bash]

If you want both to be aligned there's a more general consideration:
MinGW uses POSIX paths (with slashes). I'm not aware that you can change VS to use POSIX instead. Maybe you can convince MinGW to use Windows paths (with backslashes). Unfortunately I've never tried that with MinGW.

Best regards,

Georg Zitzlsberger
SergeyKostrov
Valued Contributor II
86 Views

...Maybe you can convince MinGW to use Windows paths (with backslashes). Unfortunately I've never tried that with MinGW...


That would be nice. Thank you, Georg.

SergeyKostrov
Valued Contributor II
86 Views

Hi Georg,

I could replace all '\' with '/' in case ofVisual C++, but I can't reconstruct a full path in case of MinGW.

MinGW: ../../folder3/test.cpp

Visual C++: c:/folder1/folder2/folder3/test.cpp

Anyway, I'll decide if it makes sence to spend time onthese updates.

Best regards,
Sergey

Reply