From 3287796807b04d0c2df8ddd7fd58229016cce00e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 3 Aug 2016 21:31:06 +0200 Subject: [PATCH] [DEBUG] correct order of parameter in c++ gcc of rpi3 change it order of usnig parameter ==> I need to check it at the runtime now. --- zeus/AbstractFunction.cpp | 28 ++++++++++++++++++++++++++++ zeus/AbstractFunction.h | 4 ++++ zeus/AbstractFunctionTypeClass.h | 24 +++++++++--------------- zeus/AbstractFunctionTypeDirect.h | 21 +++++++++------------ 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/zeus/AbstractFunction.cpp b/zeus/AbstractFunction.cpp index 17fb4a9..d17df40 100644 --- a/zeus/AbstractFunction.cpp +++ b/zeus/AbstractFunction.cpp @@ -7,6 +7,34 @@ #include #include +static int32_t firstCall(bool& _value) { + _value = false; + return 51; +} + +static int32_t secondCall(bool& _value) { + _value = true; + return 452; +} + +static void unneededCall(int32_t _val1, int32_t _val2) { + // Nothing to do ... +} + +bool zeus::checkOrderFunctionParameter() { + static bool value = false; + static bool init = false; + if (init == true) { + return value; + } + // use a temporary variable to mermit to have multiple first call and like this permit to not need to initialize it while not really needed + bool valueTmp = false; + unneededCall(firstCall(valueTmp),secondCall(valueTmp)); + value = valueTmp; + init = true; + return value; +} + enum zeus::AbstractFunction::type zeus::AbstractFunction::getType() const { return m_type; } diff --git a/zeus/AbstractFunction.h b/zeus/AbstractFunction.h index 64e83f4..887fc1d 100644 --- a/zeus/AbstractFunction.h +++ b/zeus/AbstractFunction.h @@ -13,6 +13,10 @@ namespace zeus { + /** + * @bried check if the compilater order the function element call in order or backOrder + */ + bool checkOrderFunctionParameter(); /** * @brief Interface to store a function and call it after with a @ref zeus::Buffer */ diff --git a/zeus/AbstractFunctionTypeClass.h b/zeus/AbstractFunctionTypeClass.h index 6559c05..6895b21 100644 --- a/zeus/AbstractFunctionTypeClass.h +++ b/zeus/AbstractFunctionTypeClass.h @@ -27,19 +27,16 @@ namespace zeus { if (_obj == nullptr) { return; } - #if defined(__clang__) + ZEUS_RETURN ret; + if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; - ZEUS_RETURN ret = (*_pointer.*_func)(_obj->getParameter(idParam++)...); - #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) + ret = (*_pointer.*_func)(_obj->getParameter(idParam++)...); + } else { int32_t idParam = int32_t(sizeof...(ZEUS_TYPES))-1; - ZEUS_RETURN ret = (*_pointer.*_func)(_obj->getParameter(idParam--)...); - #else - #error Must be implemented ... - ZEUS_RETURN ret; - return; - #endif + ret = (*_pointer.*_func)(_obj->getParameter(idParam--)...); + } _interfaceClient->addAsync([=](WebServer* _interface) { _interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId()); return true; @@ -60,18 +57,15 @@ namespace zeus { if (_obj == nullptr) { return; } - #if defined(__clang__) + if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; (*_pointer.*_func)(_obj->getParameter(idParam++)...); - #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) + } else { int32_t idParam = int32_t(sizeof...(ZEUS_TYPES))-1; (*_pointer.*_func)(_obj->getParameter(idParam--)...); - #else - #error Must be implemented ... - return; - #endif + } _interfaceClient->addAsync([=](WebServer* _interface) { _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId()); return true; diff --git a/zeus/AbstractFunctionTypeDirect.h b/zeus/AbstractFunctionTypeDirect.h index 44e7399..b8b9a74 100644 --- a/zeus/AbstractFunctionTypeDirect.h +++ b/zeus/AbstractFunctionTypeDirect.h @@ -22,17 +22,16 @@ namespace zeus { if (_obj == nullptr) { return; } - #if defined(__clang__) + ZEUS_RETURN ret; + if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; - ZEUS_RETURN ret = _func(_obj->getParameter(idParam++)...); - #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) + ret = _func(_obj->getParameter(idParam++)...); + } else { int32_t idParam = int32_t(sizeof...(ZEUS_TYPES))-1; - ZEUS_RETURN ret = _func(_obj->getParameter(idParam--)...); - #else - #error Must be implemented ... - #endif + ret = _func(_obj->getParameter(idParam--)...); + } _interfaceClient->addAsync([=](WebServer* _interface) { _interface->answerValue(_obj->getTransactionId(), ret, _obj->getClientId()); return true; @@ -51,17 +50,15 @@ namespace zeus { if (_obj == nullptr) { return; } - #if defined(__clang__) + if (zeus::checkOrderFunctionParameter() == true) { // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; _func(_obj->getParameter(idParam++)...); - #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) + } else { int32_t idParam = int32_t(sizeof...(ZEUS_TYPES))-1; _func(_obj->getParameter(idParam--)...); - #else - #error Must be implemented ... - #endif + } _interfaceClient->addAsync([=](WebServer* _interface) { _interface->answerVoid(_obj->getTransactionId(), _obj->getClientId()); return true;