I am completely unexperienced in C++, I use C all the time. In my recent hobby project I need to mix in a C++ library with my C code thus forcing me to have a C++ main.cpp.
I am right now meddling my C code to compile as C++. This even works pretty well except for one problem I simply cannot solve.
This is an interrupt service incrementing my unix time variable every second and also doing a conversion into spli-up time format afterwards. Since this happens in an interrupt I set the variables as volatile.
volatile time_t UNIX_TIME = 0;
volatile struct tm TIME_CUR_LOCALTIME;
if (htim == &htim2){
UNIX_TIME++;
TIME_CUR_LOCALTIME = *localtime(&UNIX_TIME);
}
From library time.h:
struct tm *localtime (const time_t *_timer);
With gcc this compiles flawless.
g++ is a different story. It gives me the error:
error: passing 'volatile tm' as 'this' argument discards qualifiers [-fpermissive]
I tried multiple casts and stuff, the only way this starts working by itself is when I drop both volatile qualifiers. But I don't want that.
What is the correct way to get this working? I am out of ideas.
localtimein an ISR - it isn't threadsafe. Uselocaltime_rinstead. - Paul SandersTIME_CUR_LOCALTIME = (volatile struct tm)*localtime((const time_t*)&UNIX_TIME);Just trying to cast things that they will fit, but this doens't work here. - nEmai