I like to have my code warning free for VS.NET and GCC, and I like to have my code 64-bit ready.
Today I wrote a little module that deals with in memory buffers and provides access to the data via a file-style interface (e.g. you can read bytes, write bytes, seek around etc.).
As the data-type for current read position and size I used size_t since that seems to be the most natural choice. I get around the warnings and it ought to work in 64-bit as well.
Just in case: My structure looks like this:
unsigned char * m_Data;
Regarding the whether
size_t is signed or unsigned and GCC (from an old GCC manual - I'm not sure if it's still there):
There is a potential problem with the
size_ttype and versions of GCC prior to release 2.4. ANSI C requires that
size_talways be an unsigned type. For compatibility with existing systems' header files, GCC defines
stddef.hto be whatever type the system's
sys/types.hdefines it to be. Most Unix systems that define
sys/types.h, define it to be a signed type. Some code in the library depends on
size_tbeing an unsigned type, and will not work correctly if it is signed.
The GNU C library code which expects
size_tto be unsigned is correct. The definition of
size_tas a signed type is incorrect. We plan that in version 2.4, GCC will always define
size_tas an unsigned type, and the 'fixincludes' script will massage the system's
sys/types.hso as not to conflict with this.
In the meantime, we work around this problem by telling GCC explicitly to use an unsigned type for
size_twhen compiling the GNU C library. 'configure' will automatically detect what type GCC uses for
size_tarrange to override it if necessary.
If you want a signed version of
ptrdiff_t or on some systems there is a typedef for