How Intel® C++ Compiler Handles Functions declared inside functions

Reference number:
DPD200153536

In accordance with the C++ language specification, if a function declaration is encountered within a function definition, the function referenced is taken to be another member of the namespace of the containing function; regardless of whether the containing function definition is lexically within a namespace definition. The Microsoft Visual C++* compiler takes the referenced function to be a global function (not in any namespace). Functions declared in global or namespace scopes are interpreted the same way by both the Intel® C++ Compiler and the Microsoft Visual C++* compiler.

Following code illustrates the difference:--

///////f1.cpp//////////// 
#include<iostream>
using namespace std;

namespace sf1 {
void f1(){

cout<<"entered into f1" << endl;
void f2();

f2();
}
};




int main(){

sf1::f1(); 
system("pause");
return 0;
}


////////////////f2.cpp////////////////////


#include <iostream>
using namespace std;
void f2(){cout<<"entered f2" << endl;}


Using Microsoft Visual C++* compiler , output is:--
(cl decl.cpp f2.cpp)

entered into f1
entered f2
Press any key to continue . . .

Using Intel® C++ Compiler, error is:--
(icl decl.cpp f2.cpp)

: error LNK2019: unresolved external symbol "void __cdecl sf1::f2(void)" (?f2@sf1@@YAXXZ) referenced in function "void __cdecl sf1::f1(void)" (?f1@sf1@@YAXXZ)


Resolution:
This issue has been fixed in the latest 11.1 compiler update
Para obtener información más completa sobre las optimizaciones del compilador, consulte nuestro Aviso de optimización.