none
int and Int32 RRS feed

  • Question

  • Hello!

    We have int as shortcut of Int32 at this moment.

    And I have code which do some work with max value of int(get max count of digits). Is there any logic to calculate it in code instead of using constant value? Is int shortcut of Int32 on every platform and is there any changes in future?

    Sunday, January 19, 2014 3:29 PM

Answers

  • int is a language primitive. How it is mapped to .Net types (e.g. the Int32 structure) depends on the compiler. int is guaranteed to be 32 bit in the C# language standard, but not in the C++/CLI language standard (it only guaranteed to be equal or larger in size than short which is defined as 16 bit).

    Currently Microsoft's implementation C++/CLI map int to Int32. However someone else my write a compiler that has int mapping to Int64 and still be standard-compliant. 



    Visual C++ MVP



    • Marked as answer by Ruzik Monday, January 20, 2014 4:30 PM
    • Edited by Sheng Jiang 蒋晟 Monday, January 20, 2014 5:35 PM
    Sunday, January 19, 2014 4:08 PM

All replies

  • int is a language primitive. How it is mapped to .Net types (e.g. the Int32 structure) depends on the compiler. int is guaranteed to be 32 bit in the C# language standard, but not in the C++/CLI language standard (it only guaranteed to be equal or larger in size than short which is defined as 16 bit).

    Currently Microsoft's implementation C++/CLI map int to Int32. However someone else my write a compiler that has int mapping to Int64 and still be standard-compliant. 



    Visual C++ MVP



    • Marked as answer by Ruzik Monday, January 20, 2014 4:30 PM
    • Edited by Sheng Jiang 蒋晟 Monday, January 20, 2014 5:35 PM
    Sunday, January 19, 2014 4:08 PM
  • Thanks for your answer!

    One more question, please: If I compile my library in dll and try to use it from C++/CLI program as I understand I dont have any problems even this C++/CLI program will use Int64 instead of Int32 because my C# code was compile in CLI code and use Int32?

    Sunday, January 19, 2014 4:24 PM
  • once your code compiled into MSIL there is no more int.

    Your program won't misunderstand its reference, since the referenced assembly contains MSIL instead of source code. All it sees are just .Net types.



    Visual C++ MVP


    Sunday, January 19, 2014 7:42 PM