Warnings due to missing abs() overloads when compiling for Windows CE 6.0
Submitted by Richard Lang
Assigned to Nobody
Link to original bugzilla bug (#723)
Version: 3.2
Operating system: Windows
Description
Trying out Eigen v3.2.0 with a Windows CE 6.0 application, compiled with Visual Studio 2008. The eigen project's changelog has some entries that seem to indicate that Windows CE compatibility has been given some consideration.
Inserted the following code into an existing cpp source module:
#include <stdafx.h>
#include <Eigen\Dense>
using namespace Eigen;
...
float Vmid1, Vmid2, Vmid3, I1, I2, I3;
...
Matrix3f A;
A << I1, I1, 1,
I2, I2, 1,
I3, I3, 1;
Vector3f b;
b << Vmid1, Vmid2, Vmid3;
Vector3f x = A.colPivHouseholderQr().solve(b);
Our target platform is set up to cross compile for both target platform (Windows CE 6.0 on ARM926EJ-S) and desktop Windows. Compiling for desktop completes without warnings, but when compiling for target get the following warnings:
1>c:\rac 900 software\rac-717 sensing cross-functional sprint\health\external\eigen\src/QR/ColPivHouseholderQR.h(496) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1>c:\rac 900 software\rac-717 sensing cross-functional sprint\health\external\eigen\src/QR/ColPivHouseholderQR.h(496) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1>c:\rac 900 software\rac-717 sensing cross-functional sprint\health\external\eigen\src/QR/ColPivHouseholderQR.h(496) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
Looking at ColPivHouseholderQR.h line 496
if(abs(beta) > m_maxpivot) m_maxpivot = abs(beta);
Turns out that Windows CE (6.0 at least) is missing the the overloaded abs() definitions for long, float and double types that in desktop VS C++ environment are defined in ".\Microsoft Visual Studio 9.0\VC\include\math.h" and compiler is quite rightly warning on implicit type conversion required to invoke int abs(int).
Got things compiling OK by creating a header file named eigen_wince.h with the following content copied from ".\Microsoft Visual Studio 9.0\VC\include\math.h"
#pragma once
#ifndef __cplusplus
#error
#endif
#ifndef _WIN32_WCE
#error
#endif
#define EIGEN_MALLOC_ALREADY_ALIGNED TRUE
#include <yvals.h>
_STD_BEGIN
// Windows CE is missing the overloads of abs() for long, float, double etc. that are expected by Eigen library. On desktop Windows these are
// defined in math.h
inline long __CRTDECL abs(In long _X){return (labs(_X)); }
inline double __CRTDECL abs(In double _X){return (fabs(_X)); }
inline float __CRTDECL abs(In float _X){return (fabsf(_X)); }
inline long double __CRTDECL abs(In long double _X){return (fabsl(_X)); }
_STD_END
and #including it before any eigen headers.
No idea if this is a problem with more recent CE versions (7.0 and 2013).
thanks
Richard