PRB: C2059 Error Using extern "C" in .C Source Files (133070)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Editions 2.0
  • Microsoft Visual C++, 32-bit Editions 2.1
  • Microsoft Visual C++, 32-bit Editions 2.2
  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

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:
#ifdef __cplusplus
   extern "C"
#endif
				

STATUS

This behavior is by design.

MORE INFORMATION

Sample Code to Reproduce Behavior

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

#include <windows.h>

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

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

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kberrmsg kbLangCPP kbprb KB133070 kbAudDeveloper