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 ect.).
As the data-type for current read position and size I used size_t since that seemes 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:
typedef struct
{
unsigned char * m_Data;
size_t m_CurrentReadPosition;
size_t m_DataSize;
} MyMemoryFile;
The sign-ness (is this the correct word btw?) of size_t seems not to be defined in practice. A Google code-search proved that.
Now I'm in a dilemma: I want to check additions with size_t for overflows because I have to deal with user supplied data and third party libraries will use my code. However, for the overflow check I have to know the sign-ness. It makes a huge difference in the implementation.
So - how the heck should I write such a code in a platform and compiler independent way?
Can I check the sign-ness of size_t at run or compile-time? That would solve my problem. Or maybe size_t wasn't the best idea at the first place?
Any ideas?
EDIT: I'm looking for a solution for the C-language!