Compiler Error C2128

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C2128.

function' : alloc_text/same_seg applicable only to functions with C linkage

pragma alloc_text can only be used with functions declared to have C linkage.

The following sample generates C2128:

// C2128.cpp  
// compile with: /c  
  
// Delete the following line to resolve.  
void func();  
// #pragma alloc_text("my segment", func)   // C2128  
  
extern "C" {  
void func();  
}  
  
#pragma alloc_text("my segment", func)  
void func() {}  

Show: