I’m noticing some inconsistent compiler warnings. In short, some inline functions (but not others declared and implemented in the exact same way) are being marked with a warning stating that they are “declared but never defined”. As an example,
timer.h:
/**
* Get the time since the timer was first initialized
*
* @param timer The timer
*/
inline long timer_GetDTFromStart(timer *timer);
timer.c:
/**
* Get the time since the timer was first initialized
*/
long timer_GetDTFromStart(timer *timer)
{
return millis() - timer->firstCalled;
}
In the header file timer.h, this function is marked as “declared but never defined”. If I include the header file in a separate source file (not timer.c), autocomplete properly finds the definition in timer.c. The compiler marks this function with the warning (and others in timer.h), but does not mark any other functions in any other files. If I recompile without having made any changes, the warnings go away. Is this something that’s being tracked, or am I implementing my functions incorrectly?
Hi @rbenasutti,
Sorry about the delayed response - classes have just started up so I’ve been running around a bunch and haven’t had time to look at the forums much.
I investigated your issue. From what I’ve gathered, the accepted GNU99 method of implementing a shared inline function is to place the function body in the header file, like so:
timer.h:
#ifndef _TIMERS_H_
#define _TIMERS_H_
// ... other definitions (like timer)
inline long timer_GetDTFromStart(timer *timer)
{
return millis() - timer->firstCalled;
}
// ... more definitions
#endif
And then in any .c file,
#include "timer.h"
// ...
void myfunc()
{
long dt = timer_getDTFromStart(mypointer);
}
If you’d like to investigate some acceptable ways are of programming inline functions in C are on your own, you can search around for GNU99 C inline functions. The PROS compiler actually is just the standard GCC compiler built for ARM devices.
Okay, thank you for investigating. I could define my inline functions in their header file, but I brought this question up because the compiler’s warning is inconsistent. In other files, I define and implement inline functions in the same manner; however, these functions do not receive a warning. This inconsistent behavior leads me to believe that there is a bug somewhere.
Yup, I’d recommend investigating with GCC. I would imagine they’re consistent but not in the manner you’re expecting since GCC tends to be a pretty thoroughly vetted compiler.
It’s also possible that Eclipse itself isn’t properly interpreting your code since it uses its own non-GCC based syntax analysis library.
If you want to try to investigate on your own, see if you can get the warnings by compiling via the terminal or if it only occurs with Eclipse. Eclipse will add its own warning/error messages on top of the compilation output so this would help you narrow down if its an issue within Eclipse or more of a GCC problem.