Signed / unsigned comparision

Signed / unsigned comparision

Anonymous
Not applicable
856 Views
7 Replies
Message 1 of 8

Signed / unsigned comparision

Anonymous
Not applicable


Im in the process of converting my app to 64bit, and was wondering what is the best practise way of doing the following;



{color:#3366ff}someMethod(int index){color}


{color:#3366ff} if (index < acdbPolyLine.numVerts()){color}

{color:#3366ff} //do something

}{color}




where 'index' is a signed integer and NumVerts() returns an unsigned integer.

a similar situation being



{color:#3366ff}for (int index = 0; index < numVerts(); index++){color}





is an (int) cast on numVerts() sufficient?

Thanks

Edited by: petepete on Dec 17, 2009 11:46 AM
0 Likes
857 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
I've been using size_t
0 Likes
Message 3 of 8

Anonymous
Not applicable
Why not just make index an unsigned int?
0 Likes
Message 4 of 8

Anonymous
Not applicable
I guess because on a 64 bit machine, an array can grow larger (in therory) than an unsigned int.

from the ARX docs
"The C++ size_t type is defined as the result of the sizeof operator and can contain the size of any object. STL and MFC containers typically return their size as a size_t value. In the IA-32 programming model, size_t is 32 bits wide. In X64, it is 64 bits wide."
0 Likes
Message 5 of 8

Anonymous
Not applicable
Because an unsigned int is not a platform-dependent type.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6309789@discussion.autodesk.com...
Why not just make index an unsigned int?
0 Likes
Message 6 of 8

Anonymous
Not applicable
Ah. Yeah, I kind of disregarded the name of the variable. Assuming index is an array index, then index should be a size_t type and an implicit (size_t) cast should be used on the return value from NumVerts(). I was thinking more along the lines of performance, where it'd make sense to just have index be an unsigned int (assuming it doesn't ever have to be negative), which would save a cast.
0 Likes
Message 7 of 8

Anonymous
Not applicable
Actually, the platform and processor architecture determines the size of almost every integral type. The integral types defined in stdint.h are the only truly non-platform-dependent types that I know of.
0 Likes
Message 8 of 8

Anonymous
Not applicable
{quote}

Actually, the platform and processor architecture determines
the size of almost every integral type

{quote}

Actually, you're confusing the language specification with the
Microsoft Visual C++ implementation of it, where 'platform-
dependent' mainly pertains to the differences that exist between
the 32 bit x86 achitecture, and its 64 bit extensions (AMD64 and
IA64), and have little relevance to other architectures, like older
16 bit architectures, or those used in embedded systems.

On 64 bit Windows, Visual C++ uses the LLP64 data model
(most UNIX/LINUX C++ compilers use LP64). In LLP64, all
native integral types are not platform-dependent, and have the
same size on 32 and 64 bit platforms.

In LP64, the only native integral type whose size is platform-
dependent is a long.

The data model used by the compiler determines the size of
native types and whether they are platform-dependent, or not.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
0 Likes