As part of stats tracking/storing for my game and, working in Tier 2, I am using the time() function to get the unix time (which is used in several AppGameKit time related functions). This function returns a type of time_t. And therein lies the issue.
On Windows 7 (64bit), time_t comes up as using 8 bytes. In iOS, Mac and Android it is 4 bytes.
In all platforms, int and long are the same size, 4 bytes. We don't worry about the unsigned versions when considering comparison to time_t because time() just might return -1.
This is not necessarily an issue until 2038, when 4 bytes won't be big enough to hold the unix time and we will need 8 bytes.
Since the size of time_t is based on the native compilers, in theory this will be fixed as all systems get updated (or are created new). And the result will be to break files and apps that explicitly store the value in 4 bytes.
Since that is 25 years down the road, I won't sweat if for the moment.
But, it is something everyone is going to start worrying about sometime in the future.
EDIT: I tested and fixed the function to work
Here is a quicky function for handling the issue for AppGameKit files (all assume that the passed file id points to a validly open file in the appropriate input/output mode):
void put_unixtime_to_file(UINT iFileID,time_t ttval)
{
// local variables
unsigned long long tmpll;
unsigned int lsb,msb;
// make sure we have full bits
tmpll = (unsigned long long)ttval;
// get the upper and lower set of 4 bytes
msb = (unsigned int)((tmpll&0xFFFFFFFF00000000)>>32);
lsb = (unsigned int)(tmpll&0x00000000FFFFFFFF);
// output to the file
agk::WriteInteger(iFileID,lsb);
agk::WriteInteger(iFileID,msb);
}
time_t get_unixtime_from_file(UINT iFileID)
{
// local variables
unsigned long long tmpll;
unsigned int lsb,msb;
time_t ttval;
// read the two sets of 4 bytes
lsb = (unsigned int)agk::ReadInteger(myFid);
msb = (unsigned int)agk::ReadInteger(myFid);
// convert the values
tmpll = (((unsigned long long)msb)<<32)+((unsigned long long)lsb);
ttval = (time_t)tmpll;
// all done
return ttval;
}
There might be an issue when the local system goes from 4 to 8 bytes for time_t and the stored values had the bit 32 set to 1 (indicating negative). Ideally, you don't store invalid time values (time() returns -1 on error).
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master