Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. MC++ wrapping mytesries

MC++ wrapping mytesries

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++
4 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    Take a look at this MC++ class :-

    public \_\_gc class Class2
    {
    public:
        int Abc()
        {
            int y=8;
            return y;
        }
    };
    

    Now here is some C# code that instantiates this class :-

    Class2 c1 = new Class2();
    int y=c1.Abc();
    

    This is confusing to me. Abc() returns an int and not an Int32. It returns a C++ int. Now we know that the C# int actually maps to a .NET Int32. What puzzles me is how the C++ int auto-converts into a C# int which auto-boxes to a Int32!


    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

    R J 2 Replies Last reply
    0
    • N Nish Nishant

      Take a look at this MC++ class :-

      public \_\_gc class Class2
      {
      public:
          int Abc()
          {
              int y=8;
              return y;
          }
      };
      

      Now here is some C# code that instantiates this class :-

      Class2 c1 = new Class2();
      int y=c1.Abc();
      

      This is confusing to me. Abc() returns an int and not an Int32. It returns a C++ int. Now we know that the C# int actually maps to a .NET Int32. What puzzles me is how the C++ int auto-converts into a C# int which auto-boxes to a Int32!


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #2

      There is no mystery C++ .NET C# int -> System.Int32 -> int System::String->System::String->string So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int.

      N 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        There is no mystery C++ .NET C# int -> System.Int32 -> int System::String->System::String->string So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Rama Krishna wrote: So C++ compiler actually emits metadata as System.Int32. C# compiler reads System.Int32 and maps it to int. Thanks Rama!!! Nish


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        1 Reply Last reply
        0
        • N Nish Nishant

          Take a look at this MC++ class :-

          public \_\_gc class Class2
          {
          public:
              int Abc()
              {
                  int y=8;
                  return y;
              }
          };
          

          Now here is some C# code that instantiates this class :-

          Class2 c1 = new Class2();
          int y=c1.Abc();
          

          This is confusing to me. Abc() returns an int and not an Int32. It returns a C++ int. Now we know that the C# int actually maps to a .NET Int32. What puzzles me is how the C++ int auto-converts into a C# int which auto-boxes to a Int32!


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          J Offline
          J Offline
          Joao Vaz
          wrote on last edited by
          #4

          int doesn't exist in .NET , the closest is "native int" used with p/invoke and com interop scenarios ... The System.Int32 is the real datatype , int is simply a "alias". For real interop with different languages used with the same project we should use the real ones, not the fakes , it's helps a lot :-) I'm be reading about IL code generation and CLR internals , and in fact .NET is a fascinating beast :omg: Microsoft have done a great work :-D Cheers, Joao Vaz A person who is nice to you, but rude to the waiter, is not a nice person - Natalie Portman (Padme/Amidala of Star Wars)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups