Hey All,
When I was using Managed C++ back in the old days of VS03, I remember being very careful to use Int16 instead of short, and Strings instead of std::strings. I'm wondering how much of a difference that makes w/ the new CLI. Is "int" equivalent to "Int32" as far as garbage collection and such
Also, I caught myself doing this today when I declare variables.
String ^str;
but when i do my arrays, I put the handle like this...
array<String^>^ str;
Where is the 'proper' place to put the cap

C++/CLI Types
FlemmingLaugesen
With C++/CLI, is it kosher to concat strings with the plus "+" sign, or is that frowned upon and String::Concat prefered
Kamen
Yes, + works fine with Strings but if are doing a lot of concatenations you should look into using StringBuilder class and its Append methods because it's more efficient.
srichand
MA2005
The standard just defines something like this
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
DazlerD
Hi,
I'm not sure about int. That is always a beast in C/C++ as its size is not defined. On 32 bit systems it is generally 32 bit, but on 16 or 64 bit systems it might be 16 oder 64. So long should be better. I guess that IJW should ensure that long will be Int32 when used in managed code.
The position of ^ is really up to you. My argument for placing it near to the variable is, that if I define more than one variable comma separated, then the first ^ would only belong to the first variable. So you have to repeat it for every variable like so:
String ^s1, ^s2;
If I follow my preference with your array, I would use: array<String^> ^str; // hmm I would use str as variable name for an array, but ;)
But I am not so strict with that. Often I find myself putting ^ and * to the type when defining a single variable and putting it to the variable when using more than one separated by comma.
--
SvenC
Devendra Desaine
SvenC, you're right about int not having a fixed size but at least the VC++ compiler in both 32 and 64 bit versions defines int as being 32 bit and this is not going to change from a version to another of VC++ (16 bit systems are out of the question, there is no CLR for 16 bit systems). The only "beast" is the long data type that unlike in C# in VC++ is 32 bit on both 32 and 64 bit versions so if you need a 64 bit integer you need to use long long or __int64 or System.Int64.
As far as I know int is 32 bit on other systems too (Linux/GCC) but long is 64 bit on a 64 bit system instead of just 32 like in Windows/VC++.
Aaron Oneal
int is Int32 and short is Int16. You can test this easily with code like this:
int
main(array<System::String ^> ^args){
int d; short s;Console::WriteLine(s.GetType()->FullName);
Console::WriteLine(d.GetType()->FullName);
return 0;}
String is NOT the same as std::string. Unlike int and short which are "built-in" types String and std::string are just classes from different libraries (.NET Framework/STL).
"Where is the 'proper' place to put the cap "
From the compiler point of view it does not matter so it's just a matter of taste like in the case of * and &. I for example never put these next to the type but next to the variable. Why Because this would suggest that I declare 2 pointers but in fact I'm just declaring a pointer and an int:
int* a,b;
so I always do
int *a, b;
(if I really do it, usually I avoid this kind of declarations).
To keep things consistent I also put a space between the type and the cap in the case of arrays:
array<String ^> ^strings;
But other people may have different opinions...