Customers




Developers Resources

Blog

05.02.2010 /Wp64 switch and template processing error
While maintaining the analyzer Viva64 (included into PVS-Studio) we often comment upon the switch /Wp64 of Microsoft Visual C++.»

03.02.2010 Parallel notes N1 - OpenMP technology
In the next few posts we will tell you about using multi-core processors in practice.»

29.01.2010 64-bit technologies - one more trend in the modern software
In the blogs and forums, there is much discussion of multi-core processors as an evident step of computer system development.»

Blog RSS

News

2.02.2010 "Lessons of 64-bit C/C++ software development" are now available on our site.»

1.02.2010 PVS-Studio 3.45 New Version Released!»

21.01.2010 PVS-Studio 3.44 New Version Released!»

News RSS

Articles

10.12.2009 PVS-Studio FAQ
This paper contains some questions and answers about PVS-Studio code analyzer by OOO "Program Verification Systems".»

09.12.2009 VivaCore FAQ
This paper contains some questions and answers about VivaCore C/C++ code analysis library by OOO "Program Verification Systems"»

23.11.2009 PVS-Studio: using the function "Mark as False Alarm"
The article describes and demonstrates by an example the use of PVS-Studio 3.40 new function "Mark as False Alarm". »

Articles RSS

Bookmark and Share

size_t

size_t. A basic unsigned integer C/C++ type. It is the type of the result returned by sizeof operator. The type's size is chosen so that it could store the maximum size of a theoretically possible array of any type. On a 32-bit system size_t will take 32 bits and on a 64-bit one - 64 bits. In other words, a pointer can be safely put inside size_t type (an exception is class-function-pointers but this is a special case). size_t type is usually used for loop, array indexing, size storage and address arithmetic. Although size_t can store a pointer, it is better to use another unsinged integer type uintptr_t for that purpose (its name reflects its capability). In some cases using size_t type is more effective and safe than using a more habitual for the programmer unsigned type.

In the terms of static analyzer PVS-Studio, type size_t refers to memsize-types. The analyzer includes Viva64 system for detailed error detection in 64-bit programs and for code optimization. Many diagnostic messages shown by Viva64 analyzer relate to recommendations on using memsize-types. Using memsize-types (such as size_t, ptrdiff_t, INT_PTR) instead of 32-bit types in 64-bit programs allows you to:

  1. enable the compiler to build a simpler and consequently faster code which will have no unnecessary conversions of 32-bit and 64-bit data. It is especially useful when operating with address arithmetic and array indexing;
  2. avoid some errors when processing a large size of input data when the number of the elements being processed excesses the number UINT_MAX;
  3. avoid some other more specific errors;
  4. make the code more portable among 64-bit versions of Windows and Linux systems which use different data models. Thus, for example, for indexing large arrays in Linux systems you can use unsigned long type while in Windows it is impossible.

To learn more about the errors you can avoid when using size_t type and also how this type allows improving and optimizing your 64-bit programs, see the articles given in the references.

If you are planning to start developing 64-bit projects or porting the existing 32-bit projects on 64-bit systems, we would like to offer you purchasing PVS-Studio analyzer which will simplify this task greatly and allow you to avoid the long period of searching hidden errors.

References

  1. About size_t and ptrdiff_t
  2. Optimization of 64-bit programs
  3. Seven Steps of Migrating a Program to a 64-bit System
  4. A 64-bit horse that can count
  5. 20 issues of porting C++ code on the 64-bit platform

Powered by RSDN Authoring Pack