can't reference *literal* in an unmanaged function???

B

Ben Voigt

This smells like a bug to me, since literals are substituted at compile
time. I'm using VS2005 SP1 beta.

// literal_unmanaged.cpp : main project file.

ref class TheClass

{

literal int ExitCode = 0;

};

#pragma unmanaged

int main()

{

return TheClass::ExitCode;

}


1>------ Build started: Project: literal_unmanaged, Configuration: Debug
Win32 ------

1>Compiling...

1>literal_unmanaged.cpp

1>.\literal_unmanaged.cpp(12) : error C3821: 'TheClass': managed type or
function cannot be used in an unmanaged function
 
G

Gary Chang[MSFT]

Hi Ben,
1>.\literal_unmanaged.cpp(12) : error C3821: 'TheClass':
managed type or function cannot be used in an unmanaged function.

I think the compiler complains about you cannot access a literal which
defines inside a managed type within an unmanaged code block, it breaks the
compiler's rule.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Ben Voigt

"Gary Chang[MSFT]" said:
Hi Ben,
1>.\literal_unmanaged.cpp(12) : error C3821: 'TheClass':
managed type or function cannot be used in an unmanaged function.

I think the compiler complains about you cannot access a literal which
defines inside a managed type within an unmanaged code block, it breaks
the
compiler's rule.

But why does the rule apply to literals? Using a literal does not require
accessing a managed object, in contrast to static field access which
requires IL (because static field references interact with class
initializers, GC, etc, etc). At least the C# compiler simply substitutes
the literal value at compile time (IL generation, not JIT), why can't the
C++ compiler do likewise? A literal member of integral type should be
considered a constant integral expression and all that implies (use to
declare arrays, as a typedef parameter, etc.)
 
G

Gary Chang[MSFT]

Hi Ben,

I understand your concern. But your program is not a pure managed one, the
problem is happens inside the native code. That literal is defined within
the managed code, which the unmanage code unable to reference it by the
native code compiler rule. Iam afraid this behavior is by design.

I suggest you can also submit this issue to our product feedback center,
our development team may communicate with you directly on the issue there:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210


Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top