Microsoft Knowledge Base Email Alertz

KBAlertz.com: VC++ 7.1 Internal Compiler Error C1001 compiling ANSI string where System::String expected for variable argument

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 956367 - Last Review: July 31, 2008 - Revision: 1.0

VC++ 7.1 Internal Compiler Error C1001 compiling ANSI string where System::String expected for variable argument

Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action



You attempt to compile a Visual C++ 7.1 mixed-mode program in which an ANSI string literal is passed to a function where a System::String is expected, and this is passed on to a function with variable arguments (,...).

For instance, suppose you have a function that resembles this:

void MyFunction( System::String * pText )
{
    ATLTRACE("MyFunction called with %s\n", pText);
    \\ Do something else
    return;
}

and you may call it with something like this:

MyFunction("Here is an ANSI string literal");

Result

You may get an Internal Compiler Error similar to this:


C:\Program Files\Microsoft Visual Studio .NET 2003\vc7\atlmfc\include\atltrace.h(167) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'f:\vs70builds\3077\vc\Compiler\Utc\src\P2\imeta.cpp', line 548)

Cause



In VC++ 7.1 (and .NET 1.1), when an ANSI string literal is passed to a function expecting a System::String *, the compiler has to perform a conversion to generate the String*.

If that String* parameter is passed to a variable argument function (such as the one from the ATLTRACE macro), the compiler has to generate special code to make that happen, because vararg functions are a complex special case. To do this, the compiler uses APIs from the Common Language Runtime. The compiler and the CLR communicate via metadata tokens.  In some cases, the CLR API may fail if it doesn't recognize a token that the compiler has used previously. The VC++ 7.1 compiler did not properly handle this API failure, and consequently failed with an ICE.

Resolution



This problem is fixed in Visual Studio 2005 and .NET Framework 2.0.  Numerous improvements have been made to the compilers and .NET Frameworks, including much better interoperability between native and managed code (C++/CLI), and handling of loader locks, just to name a couple. The recommended resolution would be to upgrade to Visual Studio 2005 or later (such as VS 2008).

If you must stay with VC++ 7.1, the simplest solution is to pass a string literal that is a .NET string (System::String) instead of an ANSI string (char *).  To do this, simply prefix the string with 'S':

MyFunction(S"Here is a .NET string literal");

Alternatively, you could make sure that your string is properly converted to an intermediate String variable before passing to a vararg function, or just avoid using vararg functions with .NET types.

More Information

How to convert from System::String* to char* in Visual C++ (http://kbalertz.com/Feedback.aspx?kbNumber=311259)
String Literals (http://msdn.microsoft.com/en-us/library/ms235263.aspx)
What's New in Visual Studio 2005 (http://msdn.microsoft.com/en-us/library/88fx1xy0(VS.80).aspx)
What's New in Visual Studio 2008 (http://msdn.microsoft.com/en-us/library/bb386063.aspx)

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

APPLIES TO
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Professional Special Edition
  • Microsoft Visual Studio .NET 2003 Service Pack 1
  • Microsoft Visual Studio .NET 2003 SP1
Keywords: 
kbnomt kbrapidpub KB956367
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please