As I'm writing applications using C++ .NET framework I want to ask a question.
When I am writing code exactly for "for loop" I always use this style of coding:
for( int i=0; i<somevalue; ++i ) {
// Some code goes here.
}
but as I am using C++ .NET I can write
for( System::Int32 i=0; i<somevalue; ++i ) {
// Some code goes here.
}
I think there are no difference Am I right ? If no can you explain whats the difference between this two ways and. witch one is more effective ?
The C++/CLI language specification (p. 50) says that:
The fundamental types map to corresponding value class types provided by the implementation, as follows:
signed charmaps toSystem::SByte.unsigned charmaps toSystem::Byte.- If a plain
charis signed,charmaps toSystem::SByte; otherwise, it maps toSystem::Byte.- For all other fundamental types, the mapping is implementation-defined [emphasis mine].
This differs from C#, in which int is specifically defined as an alias for System.Int32. In C++/CLI, as in ISO C++, an int has "the natural size suggested by the architecture of the execution environment", and is only guaranteed to have at least 16 bits.
In practice, however, .NET does not run on 16-bit systems, so you can safely assume 32-bit ints.
But be careful with long: Visual C++ defines it as 32-bit, which is not the same as a C# long. The C++ equivalent of System::Int64 is long long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With