Confused on usage of DS3232RTC library

My sketch has an RTC attached and I'm using the DS3232RTC library to interface with it. I followed the examples to get it setup (set the time and synch with my board etc). It appears to work as it should, if I power off and then back on, it sets the system time to the correctly stored RTC time. But I ran into some odd behavior while debugging a separate time-related bug.

First, my setup() has the standard init for the time:


if(timeStatus() != timeSet) {
    Serial.println("Unable to sync with the RTC");
    Serial.println("RTC has set the system time");    

But in my debugging method, where I'm trying to print out the current value of RTC.get:

void printDT(){ 
   tmElements_t tm;
   breakTime(RTC.get, tm);
   char res[14];
   sprintf(res, "%02d-%02d-%02d %02d:%02d", 0, tm.Month, tm.Day, (tm.Year+1970), tm.Hour, tm.Minute, tm.Second); 

It prints:
01-01-1970 00:34
Always the same thing...what could be going on here? How does the synch's call to RTC.get work correctly but my debug call does not?

#1 res isn't big enough to hold all that you are trying to put in it. You're cramming 14 characters in but you need to leave space for the terminating null on that string. Make res 15 characters at least.

#2 Shouldn't there be parenthesis on the function call here?

breakTime(RTC.get, tm);

Shouldn't that be:

breakTime(RTC.get(), tm);

#1) OK, will do, I wasn't aware of that thanks.

#2)hmmm, good make a good point, in the source code it is indeed get() like you would expect. I had it without the parens because I copied it from my init, which is lifted right from the examples. So is it because this:


is assigning that function as a delegate?

While my debug code is calling breakTime(time_t, tmElements_t) which just expects a time_t?

Why does it still compile then? And what exactly is it doing behind the scenes do you think when I omit the parens like that?

setSyncPeovider takes a pointer to a function. So in that case no parenthesis.

breakTime needs the return value from the function. So you need the parenthesis there.

It still compiles because it is legal. There are times where you might want to treat a pointer like a number. What is happening is that it is taking the memory address of the get function and using it like the epoch time that breakTime was expecting. breakTime sees that number thinks that what you want to use for the epoch time and goes about converting it.

ahhhh ok that makes sense, thanks