Microsoft KB Archive/133070

= PRB: C2059 Error Using extern "C" in .C Source Files =

Article ID: 133070

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * Microsoft Visual C++ 2.2
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



This article was previously published under Q133070



SUMMARY
Use of "extern "C"" in source files that have a .C extension causes error C2059, and results in this error message:

error C2059:syntax error:'string'



CAUSE
In the C language, the string-literal "C" is not recognized. It is used in C++ to prevent name decoration.



RESOLUTION
Remove the string-literal "C" in extern declarations, or use the following in the function declaration: extern "C"
 * 1) ifdef __cplusplus
 * 1) endif



STATUS
This behavior is by design.



Sample Code to Reproduce Behavior
/* Compile options needed: None The following program reproduces the behavior if the source file has .C extension


 * 1) include 

extern "C" _declspec(dllexport) BOOL WINAPI function1(void);

BOOL WINAPI DllMain ( HINSTANCE hInst, DWORD dwReason,                       LPVOID lpReserved) {  // Other required code goes here. return TRUE; }

Additional query words: 9.0 9.00 9.1 9.10

Keywords: kberrmsg kblangcpp kbprb KB133070

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.