mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-04 05:05:19 +08:00
param: fix param_get_cplusplus type check
This commit is contained in:
@@ -452,7 +452,7 @@ __END_DECLS
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#if defined(__cplusplus) && !defined(PARAM_IMPLEMENTATION)
|
||||||
#if 0 // set to 1 to debug param type mismatches
|
#if 0 // set to 1 to debug param type mismatches
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#define CHECK_PARAM_TYPE(param, type) \
|
#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().
|
// 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
|
// 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
|
// 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);
|
CHECK_PARAM_TYPE(param, PARAM_TYPE_FLOAT);
|
||||||
return param_get(param, (void *)val);
|
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);
|
CHECK_PARAM_TYPE(param, PARAM_TYPE_INT32);
|
||||||
return param_get(param, (void *)val);
|
return param_get(param, (void *)val);
|
||||||
}
|
}
|
||||||
#undef CHECK_PARAM_TYPE
|
#undef CHECK_PARAM_TYPE
|
||||||
|
|
||||||
|
#define param_get(param, val) param_get_cplusplus(param, val)
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
* and background parameter saving.
|
* and background parameter saving.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define PARAM_IMPLEMENTATION
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "param_translation.h"
|
#include "param_translation.h"
|
||||||
#include <parameters/px4_parameters.h>
|
#include <parameters/px4_parameters.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user