Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
 Static Const Int Linkage Is No Long...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual C++ Concepts: Porting and Upgrading 
Static Const Int Linkage Is No Longer Literal 

Declaration of a constant member of a class has changed from Managed Extensions for C++ to Visual C++ 2005.

Although static const integral members are still supported, their linkage attribute has changed. Their former linkage attribute is now carried in a literal integral member. For example, consider the following Managed Extensions class:

public __gc class Constants {
public:
   static const int LOG_DEBUG = 4;
};

This generates the following underlying CIL attributes for the field (note the literal attribute):

.field public static literal int32 
modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) STANDARD_CLIENT_PRX = int32(0x00000004)

While this still compiles under the new syntax:

public ref class Constants {
public:
   static const int LOG_DEBUG = 4;
};

it no longer emits the literal attribute, and therefore is not viewed as a constant by the CLR runtime:

.field public static int32 modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) STANDARD_CLIENT_PRX = int32(0x00000004)

In order to have the same inter-language literal attribute, the declaration should be changed to the newly supported literal data member, as follows,

public ref class Constants {
public:
   literal int LOG_DEBUG = 4;
};

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker