Thursday, 22 August 2013

Understanding c++ function with missing variables in Arduino's RTClib

Understanding c++ function with missing variables in Arduino's RTClib

I'm trying to understand a function call that doesn't supply the required
parameters but seems to work. The code is in an Arduino library called
RTClib. Why/how does this work????
The function making the call:
uint8_t DateTime::dayOfWeek() const {
uint16_t day = date2days(yOff, m, d);
return (day + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6
}
The function being called:
static uint16_t date2days(uint16_t y, uint8_t m, uint8_t d) {
if (y >= 2000)
y -= 2000;
uint16_t days = d;
for (uint8_t i = 1; i < m; ++i)
days += pgm_read_byte(daysInMonth + i - 1);
if (m > 2 && y % 4 == 0)
++days;
return days + 365 * y + (y + 3) / 4 - 1;
}
The full library: https://github.com/adafruit/RTClib

No comments:

Post a Comment