Tool/software: TI C/C++ Compiler
I have an inline function in a header:
template <unsigned Class, unsigned Index>
inline bool hasFeatureBuffered()
{
static bool const featureAvailable =
hasFeature(getFeatureClass(Class), Index);
return featureAvailable;
}
I get a bunch of errors:
<Linking>
error #10056: symbol "initialization guard variable for bool
hasFeatureBuffered<N1, N2>() [with N1=(unsigned int)8, N2=(unsigned
int)52]::featureAvailable" redefined: first defined in
"./ServoLibrary/service/sensor/ProxiedAdConverter.obj"; redefined in
"./application/InverterSettings.obj"
error #10056: symbol "initialization guard variable for bool
hasFeatureBuffered<N1, N2>() [with N1=(unsigned int)8, N2=(unsigned
int)45]::featureAvailable" redefined: first defined in
"./ServoLibrary/service/timing/timing_unit/CTimingUnit.obj"; redefined in
"./platform/servo/common/application/tasksIsd510.obj"
I'm stuck on C2000 6.1.0 for now.
It looks to me like the linker fails to merge the featureAvailable instances from different translation units. My understanding of the language is that the inline keyword takes the ODR out of effect and the linker has to merge these instances.
A solution (viable here), because the hasFeature() call has no side effects, is to make it a static inline. Declaring a static function in a header is a vomit inducing prospect though and the waste of memory is at least distasteful.
Is there an elegant way out of this conundrum?