param: fix param_get_cplusplus type check

This commit is contained in:
Beat Küng
2020-02-24 16:03:36 +01:00
committed by Daniel Agar
parent b54e5a1c23
commit a2b2605443
2 changed files with 6 additions and 3 deletions
+5 -3
View File
@@ -452,7 +452,7 @@ __END_DECLS
#ifdef __cplusplus
#if defined(__cplusplus) && !defined(PARAM_IMPLEMENTATION)
#if 0 // set to 1 to debug param type mismatches
#include <cstdio>
#define CHECK_PARAM_TYPE(param, type) \
@@ -467,18 +467,20 @@ __END_DECLS
// param is a C-interface. This means there is no overloading, and thus no type-safety for param_get().
// So for C++ code we redefine param_get() to inlined overloaded versions, which gives us type-safety
// w/o having to use a different interface
static inline int param_get(param_t param, float *val)
static inline int param_get_cplusplus(param_t param, float *val)
{
CHECK_PARAM_TYPE(param, PARAM_TYPE_FLOAT);
return param_get(param, (void *)val);
}
static inline int param_get(param_t param, int32_t *val)
static inline int param_get_cplusplus(param_t param, int32_t *val)
{
CHECK_PARAM_TYPE(param, PARAM_TYPE_INT32);
return param_get(param, (void *)val);
}
#undef CHECK_PARAM_TYPE
#define param_get(param, val) param_get_cplusplus(param, val)
#endif /* __cplusplus */
#endif
+1
View File
@@ -41,6 +41,7 @@
* and background parameter saving.
*/
#define PARAM_IMPLEMENTATION
#include "param.h"
#include "param_translation.h"
#include <parameters/px4_parameters.h>