I can't get my julian day function working. With gcc and msvc++ it works perfectly. In the Keil compiler it doesn't. The date 05/21/2003 should produce 2452781 julian days, instead it produces 27950. And sometimes the month parameter is hosed. It's supposed to be 5, but a lot of the times it's like 31713 or some crazy value. Program Size: data=127.3 xdata=8174 code=36284
// Julian day number 0 corresponds to -4713-11-24 Gregorian. The // Julian day (jd) is computed from Gregorian day, month and year (d, // m, y) as follows: ULONG julian(int month, int day, int year) { return ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 + ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 + d - 32075; }
damnit, nevermind. I forgot that 'int' on this processor is only 16-bits. I changed 'int' to 'long' and it works.
"I forgot that 'int' on this processor is..." As I repeated on this very forum only last week: "I recommend that you should *always* encapsulate *all* your compiler dependencies in #defines!!" Here: http://www.keil.com/forum/docs/thread31.asp#msg11352
Okay. I've got this. I'm sure it can be improved upon. This is in a header file that is shared between MSVC++ and the Keil.
// BOOL is 4 bytes in msvc++, 1 byte on keil // UINT is 4 bytes in msvc++, 2 bytes on keil // // Define some useful types #ifndef _WINDOWS_ typedef unsigned char BYTE; typedef unsigned int UINT; typedef unsigned long ULONG; typedef unsigned char BOOL; typedef unsigned int WORD; typedef unsigned long DWORD; typedef unsigned int USHORT; #endif
"What do you do about signed stuff?" How about S8, S16, S32? "What about BOOL?" That would be 'bit'. Stefan
View all questions in Keil forum