Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Full compatibility with Microsoft and GCC C++ compilers for a macro __FILE__ is not supported

SergeyKostrov
Valued Contributor II
572 Views

A full compatibility with Microsoft and GCC C++ compilers for a macro __FILE__ is not supported. I'd like to bring attention of Intel C++ compiler team even if it is a small issue. Here are examples: [ Intel C++ compiler ] Source File Name: .\../../Test/BaseSetTest.cpp [ Microsoft C++ compiler ] Source File Name: c:\workenv\test\basesettest.cpp [ MinGW C++ compiler ( GCC for Windows ) ] Source File Name: ../../Test/BaseSetTest.cpp

0 Kudos
11 Replies
SergeyKostrov
Valued Contributor II
572 Views
Here is a test-case: [ Test-case ] #include "stdio.h" void main( void ) { #ifdef _DEBUG printf( "Source File Name: %s\n", __FILE__ ); #else printf( "Source File Name: %s\n", "null" ); #endif }
0 Kudos
Judith_W_Intel
Employee
572 Views

 

Sorry but I need more information to reproduce the problem. Please provide the command line options used.

This is what I see:

!% cat ../test.cpp

#include "stdio.h"

int main()
{
 printf( "Source File Name: %s\n", __FILE__ );
 return 0;
}

!% cl D:/TRACKER/FORUM/test.cpp && ./test
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
Source File Name: D:/TRACKER/FORUM/test.cpp
!% icl D:/TRACKER/FORUM/test.cpp && ./test
Intel(R) C++ Compiler XE for applications running on IA-32, Version Mainline Bet
a Build x
Built Jan 28 2013 19:53:03 by jward4 on JWARD4-DESK in D:/workspaces/cfe/dev
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:test.exe
test.obj
Source File Name: D:/TRACKER/FORUM/test.cpp
!% cl ../test.cpp && ./test
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
Source File Name: ../test.cpp
!% icl ../test.cpp && ./test
Intel(R) C++ Compiler XE for applications running on IA-32, Version Mainline Bet
a Build x
Built Jan 28 2013 19:53:03 by jward4 on JWARD4-DESK in D:/workspaces/cfe/dev
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:test.exe
test.obj
Source File Name: ../test.cpp
!%

 

0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
Any compiler options could be used but the most important is a preprocessing macro _DEBUG ( has to be defined for Debug configuration ). Do you want me to create a VS and makefile based test-cases? Please let me know.
0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
VS 2005 projects with test-cases for Intel and Microsoft C++ compilers attached.
0 Kudos
Judith_W_Intel
Employee
572 Views

 

Yes please create a Makefile or show me the icl and cl command line options used. I don't have acess to a Visual Studio environment.

thanks,

Judy

0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
Hi Judy, >>...Yes please create a Makefile or show me the icl and cl command line options used. I don't have acess to a Visual Studio >>environment... Sorry, I didn't know it and I'll create a Makefile tomorrow.
0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
>>>>...Yes please create a Makefile or show me the icl and cl command line options used. I don't have acess to a Visual Studio >>>>environment... >> >>Sorry, I didn't know it and I'll create a Makefile tomorrow. Let me provide command lines instead of a makefile. So, if the test case: #include "stdio.h" void main( void ) { #ifdef _DEBUG printf( "Source File Name: %s\n", __FILE__ ); #else printf( "Source File Name: %s\n", "null" ); #endif } is saved in Test.cpp file then command lines for Intel C++ compiler are as follows: [ Debug configuration ]: icl.exe -D_DEBUG Test.cpp [ Release configuration ]: icl.exe -DNDEBUG Test.cpp
0 Kudos
Judith_W_Intel
Employee
572 Views

 

I don't see any incompatibilty with Microsoft using those command line options, i.e. the Source file name printed is the same.

!% cat Test.cpp

#include "stdio.h"

void main( void )
{
#ifdef _DEBUG
printf( "Source File Name: %s\n", __FILE__ );
#else
printf( "Source File Name: %s\n", "null" );
#endif
}
!% icl -D_DEBUG Test.cpp && ./Test.exe
Intel(R) C++ Compiler XE for applications running on IA-32, Version Mainline Bet
a Build x
Built Feb  5 2013 13:30:17 by jward4 on JWARD4-DESK in D:/workspaces/cfe/dev
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

Test.cpp
Test.cpp(4): warning #1079: return type of function "main" must be "int"
  void main( void )
       ^

Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:Test.exe
Test.obj
Source File Name: Test.cpp
!% cl -D_DEBUG Test.cpp && ./Test.exe
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Test.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Test.exe
Test.obj
Source File Name: Test.cpp
!%

The __FILE__ macro should print out the source file as specified on the command line so if you are seeing a difference between cl and icl it's probably because the command line is different. So I think this is either because you changed something in the project or the IDE converted the project incorrectly. I don't think it's a bug in the compiler itself.

Judy

 

0 Kudos
Anoop_M_Intel
Employee
572 Views

When we use the command line to create the executable, the response from icc and gcc binary are the same. When I used VS2008 IDE and created the binary using cl and icl, cl binary version was emitting absolute path of the .cpp while the icl binary version was emitting relative path to the .cpp file with reference to the location of VS project (Project working directory). Here are the outputs which I see:

cl binary output:

Source File Name: c:\temp\blah1\blah1\blah1.cpp
Press any key to continue . . .

icl binary output:

Source File Name: .\blah1.cpp
Press any key to continue . . .

Though one gives absolute path and other one gives the relative path, it does give the right path to the file. I am not sure if this is a compatibilty issue. I am attaching the sample VS2008 solution for reference. 

0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
I've explained the issue in my 1st post and provided examples. Do you see the differences in outputs? [ Intel C++ compiler ( Case 1 ) ] Source File Name: .\../../Test/BaseSetTest.cpp [ Microsoft C++ compiler ( Case 2 ) ] Source File Name: c:\workenv\test\basesettest.cpp [ MinGW C++ compiler ( GCC for Windows ) ( Case 3 ) ] Source File Name: ../../Test/BaseSetTest.cpp Then, I've been using macro __FILE__ in my sources for many-many years and I know what it does. As soon as I've integrated Intel C++ compiler to a project I've detected that compatibility of __FILE__ macro outputs is not supported. So, please try to create a directory structure similar to the Case 2, like: C:\Folder1\Folder2\Folder3\Test.cpp and compare results of your tests: Intel C++ compiler for Windows vs. Intel C++ compiler for Linux vs. Microsoft C++ compiler.
0 Kudos
SergeyKostrov
Valued Contributor II
572 Views
This is a follow up: Are there any updates on the issue? Thanks in advance.
0 Kudos
Reply