Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7679 Discussions

How could I control the format of a macro __FILE__?

SergeyKostrov
Valued Contributor II
165 Views

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
165 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
165 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
165 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