Vector::size S32?
by Gerald Fishel · in Torque 3D Professional · 01/08/2013 (3:12 pm) · 7 replies
So I'm wondering if anybody knows if there is a good reason why Vector::size returns S32 instead of U32? Everything else - including setSize - uses U32.
#2
Gerald is referring to the C++ Vector class in tVector.h. The Vector class is a template class that can take any data type defined in C++.
@Gerald,
I think it is a mistake. It should be a U32 if it can allocate U32 elements.
01/08/2013 (6:59 pm)
@Scott,Gerald is referring to the C++ Vector class in tVector.h. The Vector class is a template class that can take any data type defined in C++.
// A vector of S32 Vector<S32> S32nums; // A vector of ShapeBase objects. Vector<ShapeBase> sbObjects;
@Gerald,
I think it is a mistake. It should be a U32 if it can allocate U32 elements.
#3
01/08/2013 (7:07 pm)
I agree - a Vector template should never have a negative size. You'll find stuff like that throughout the engine though - drives me nuts.
#4
I'm going through and fixing all/most of the warnings (when warnings are not disabled) again, and one of the biggest source of warnings is what seems like a completely haphazard use of S32 and U32. And in several places F32 is actually used as an integer.
01/08/2013 (7:14 pm)
That's what I figure as well, just hoping if there *is* some reason it was done that somebody can enlighten me before I go too far ;)I'm going through and fixing all/most of the warnings (when warnings are not disabled) again, and one of the biggest source of warnings is what seems like a completely haphazard use of S32 and U32. And in several places F32 is actually used as an integer.
#5
01/08/2013 (7:48 pm)
I'm glad you posted this. Now help me understand why this is obvious to everyone here except me? But try to keep it in Layman terms. =)
#6
The values stored in the Vector can be signed values (or any other type of value), but the size of the vector should never be less than 0.
01/08/2013 (7:53 pm)
@Scott - a "Vector" in this case is a sort of managed array, it's simply a collection of values. The "size" method of a Vector returns the number of elements in the array. Having a size of -1 would be similar to having a carton of eggs with -1 eggs in it, it's typically not a very logical scenario to have a negative number of elements in an array ;)The values stored in the Vector can be signed values (or any other type of value), but the size of the vector should never be less than 0.
#7
But since you explained it, I get it. =)
01/08/2013 (7:57 pm)
Now that makes sense to me. I won't explain what I was thinking originally.. I wouldn't want to confuse the forum reader.But since you explained it, I get it. =)
Torque 3D Owner Scott Warren
U16 = unsigned short
U32 = unsigned int
S16 = signed short
S32 = signed int
F32 = float
F64 = double
signed: -32768 to 32767
unsigned: 0 to 65535
I'm just beginning to work with scripting. The paragraph was in the manual.
wouldn't you get a wrong value returned if you couldn't get the negative values?