Hi,
Please consider the following comments
A) Enhance PCAN-Basic Documentation on TPCANTimestamp
So far it is noted
"Calculation of total of microseconds : micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow"
I suggest to explicit hint the reader to overflow issues. For usage in C/C++ the above equation should read e.g.
"micros + 1000ULL * millis + 0xFFFFFFFF * 1000ULL * millis_overflow"
Rationale:
0xFFFFFFFF * 1000 will immediately overflow to 0xFFFFFC18
0xFFFFFFFF * 1000ULL will result in 0x3E7FFFFFC18. This 64 bit value is still large enough to be multiplied with 16 bit unsigned value millis_overflow. The same argumentation holds for 1000ULL * millis if millis is near overflow.
Keep in mind order of operations and implicit conversions, e.g. (0xFFFFFFFF * 2ULL * 2) is different from (0xFFFFFFFF * 2 * 2ULL)
B) Enhancement proposal: match constant types to related variable types
Example: TPCANStatus is of type DWORD, which is unsigned. The related constants are defined as signed types, e.g.
#define PCAN_ERROR_BUSLIGHT 0x00004
Proposal is to change also to unsigned type, i.e.
#define PCAN_ERROR_BUSLIGHT 0x00004U
Rationale:
Operations, e.g. bit test operations with ~ (NOT), cause warnings for the following type of code
TPCANStatus status;
...
status &= ~PCAN_ERROR_BUSLIGHT;
gcc: negative integer implicitly converted to unsigned type [-Werror=sign-conversion]
Of course user can prevent the warning with an explicit cast.
Best Regards
H. Müller
Comment on time calculation and constant types
Re: Comment on time calculation and constant types
Hello H.Müller,
Thanks for your comments. We will consider them.
Thanks for your comments. We will consider them.
Best regards,
Keneth
Keneth