From 50ceebc2cdcfe2c942fa2aec4797792862980f72 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Sat, 1 Jun 2013 22:44:35 +0200 Subject: [PATCH] vxWorks: long int* to int* cast on 32-bit --- pvAccessApp/ca/caChannel.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pvAccessApp/ca/caChannel.cpp b/pvAccessApp/ca/caChannel.cpp index a993a4e..24e5786 100644 --- a/pvAccessApp/ca/caChannel.cpp +++ b/pvAccessApp/ca/caChannel.cpp @@ -501,17 +501,31 @@ void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer cons { std::tr1::shared_ptr value = std::tr1::static_pointer_cast(pvStructure->getScalarArrayField("value", sT)); -#ifdef vxWorks - // dbr_long_t is defined as "int", pvData uses int32 which can be defined as "long int" (32-bit) - // this makes static cast to fail, this is a workaround (compiler will optimize this efficiently) - if (sizeof(pT) == 4) - value->put(0, count, static_cast(dbr), 0); - else -#endif value->put(0, count, static_cast(dbr), 0); } } +#ifdef vxWorks +// dbr_long_t is defined as "int", pvData uses int32 which can be defined as "long int" (32-bit) +// this makes static cast to fail, this is a workaround (compiler will optimize this efficiently) +// template +template<> +void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure) +{ + if (count == 1) + { + std::tr1::shared_ptr value = std::tr1::static_pointer_cast(pvStructure->getSubField("value")); + value->put(static_cast(dbr)[0]); + } + else + { + std::tr1::shared_ptr value = + std::tr1::static_pointer_cast(pvStructure->getScalarArrayField("value", pvInt)); + value->put(0, count, static_cast(dbr), 0); + } +} +#endif + // string specialization template<> void copy_DBR(const void * dbr, unsigned count, PVStructure::shared_pointer const & pvStructure)