I have a very simple 'issue' with LibSVM:
I am on a Mac, OSX, 10.9.5. I cloned the libSVM repo from here, and as per the instructions on the README, simply ran make.
This is supposed to compile the libSVM programs without issue, but I am getting a litany of warnings about signedness.
Needless to say, this concerns me, because of signs are changing willy nilly, I will have no faith in the classifier. Should this be something of concern, and if so, how do I go about resolving it?
Here is what I get when I run the make command from the command line:
adam-MacBook-Pro:libsvm adam$ make
c++ -Wall -Wconversion -O3 -fPIC -c svm.cpp
svm.cpp:96:26: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
head = (head_t *)calloc(l,sizeof(head_t)); // initialized to 0
~~~~~~ ^
svm.cpp:98:10: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
size -= l * sizeof(head_t) / sizeof(Qfloat);
^ ~
svm.cpp:146:54: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
~^~~
svm.cpp:1651:38: warning: implicit conversion changes signedness: 'const int' to 'unsigned long' [-Wsign-conversion]
double *alpha = Malloc(double,prob->l);
~~~~~~~~~~~~~~~~~~~~^~
svm.cpp:39:40: note: expanded from macro 'Malloc'
#define Malloc(type,n) (type *)malloc((n)*sizeof(type))
^
svm.cpp:1722:26: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
double *t=Malloc(double,l);
~~~~~~~~~~~~~~^~
svm.cpp:39:40: note: expanded from macro 'Malloc'
#define Malloc(type,n) (type *)malloc((n)*sizeof(type))
^
svm.cpp:1833:29: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
Related
I´m trying to make this project https://github.com/Slamtec/rplidar_sdk. But when i run the make command i get the following error:
In file included from src/sl_lidar_driver.cpp:40:
src/hal/event.h: In member function 'long unsigned int rp::hal::Event::wait(long unsigned int)':
src/hal/event.h:108:20: warning: conversion from 'rp::hal::Event::<unnamed enum>' to 'long unsigned int' changes value from 'rp::hal::Event::EVENT_TIMEOUT' to '4294967295' [-Woverflow]
108 | return EVENT_TIMEOUT;
| ^~~~~~~~~~~~~
src/sl_lidar_driver.cpp: In member function 'virtual sl_result sl::SlamtecLidarDriver::grabScanDataHq(sl_lidar_response_measurement_node_hq_t*, size_t&, sl_u32)':
src/sl_lidar_driver.cpp:556:34: error: narrowing conversion of 'rp::hal::Event::EVENT_TIMEOUT' from 'long long unsigned int' to 'long unsigned int' [-Wnarrowing]
556 | case rp::hal::Event::EVENT_TIMEOUT:
| ^~~~~~~~~~~~~
src/sl_lidar_driver.cpp:556:13: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295' [-Woverflow]
556 | case rp::hal::Event::EVENT_TIMEOUT:
| ^~~~
src/sl_lidar_driver.cpp: In member function 'sl_result sl::SlamtecLidarDriver::_sendCommand(sl_u16, const void*, size_t)':
src/sl_lidar_driver.cpp:1089:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<unsigned char>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
1089 | for (int pos = 0; pos < cmd_packet.size(); pos++) {
| ~~~~^~~~~~~~~~~~~~~~~~~
src/sl_lidar_driver.cpp:1058:19: warning: unused variable 'pkt_header' [-Wunused-variable]
1058 | sl_u8 pkt_header[10];
| ^~~~~~~~~~
src/sl_lidar_driver.cpp: In member function 'void sl::SlamtecLidarDriver::_ultraCapsuleToNormal(const sl_lidar_response_ultra_capsule_measurement_nodes_t&, sl_lidar_response_measurement_node_hq_t*, size_t&)':
src/sl_lidar_driver.cpp:1370:40: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
1370 | if ((dist_predict1 == 0xFFFFFE00) || (dist_predict1 == 0x1FF)) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~
src/sl_lidar_driver.cpp:1379:40: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
1379 | if ((dist_predict2 == 0xFFFFFE00) || (dist_predict2 == 0x1FF)) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~
src/sl_lidar_driver.cpp: At global scope:
src/sl_lidar_driver.cpp:72:17: warning: 'void sl::convert(const sl_lidar_response_measurement_node_hq_t&, sl_lidar_response_measurement_node_t&)' defined but not used [-Wunused-function]
72 | static void convert(const sl_lidar_response_measurement_node_hq_t& from, sl_lidar_response_measurement_node_t& to)
| ^~~~~~~
src/sl_lidar_driver.cpp:59:17: warning: 'void sl::printDeprecationWarn(const char*, const char*)' defined but not used [-Wunused-function]
59 | static void printDeprecationWarn(const char* fn, const char* replacement)
make[1]: *** [/c/rplidar_sdk/mak_common.inc:82: /c/rplidar_sdk/obj/MSYS_NT-10.0-19044/Release/sdk/src/sl_lidar_driver.o] Error 1
make[1]: Leaving directory '/c/rplidar_sdk/sdk'
make: *** [/c/rplidar_sdk/mak_common.inc:43: make_subs] Error 1
someone could tell me why i getting this error and how to solved it?
Apparently this code is not portable.
It appears to assume that a long int is 64bits (8 bytes) long, which is true on Linux and MacOS. But on Windows, a long int is only 32bits (4 bytes) long.
C and C++ have 5 integral types (ignoring the unsigned versions): char, short, int, long, long long. The C standard gives a minimum range of integers that must fit into these types, but it doesn't give a maximum. It's up to the implementation. See https://en.wikipedia.org/wiki/C_data_types#Main_types
A modern system has native support for 4 sizes of integer: 1 byte, 2 bytes, 4 bytes, 8 bytes.
So you can see that in order to map 5 types onto 4 sizes, two of the types must map to the same size.
Linux and MacOS choose to have int be 4 bytes and long and long long both be 8 bytes. Windows chooses to have int and long both be 4 bytes, and long long be 8 bytes. See https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models
If the code is written to assume that long and long long are the same size and can be used interchangeably, then you'll get errors like the ones you're seeing when you try to compile it on Windows.
I'm trying to compile https://github.com/jbeder/yaml-cpp on a Raspberry Pi, and I'm getting this error:
/home/pi/yaml-cpp/test/binary_test.cpp:11:38: error: narrowing conversion of ‘-58’ from ‘int’ to ‘char’ [-Wnarrowing]
11 | std::string input{-58, -1, -99, 109};
| ^
I gather that I should explicitly declare the numbers inside the bracket as signed chars, as some older compilers might not do so by themselves. But I am wholly unfamiliar with this syntax: What does this line actually do?
I getting below warning. How to suppress this warning?
Warning:
warning: comparison of integer expressions of different signedness: 'DWORD' {aka 'unsigned int'} and 'int' [-Wsign-compare]
Code:
DWORD exp = GetExp();
int amount = 20;
if (amount < 0 && exp < -amount)
{
...
}
If you really want to suppress it (it's not recommended, there is a reason a warning is shown, and you should instead eliminate the reason), you can do it by adding -Wno-sign-compare to the gcc command line.
I am not used to work with c++, ;)
I get the follwoing error when compiling my code on this line :
#define NUM 34
char tmp[4] = {(xorValue&0xffff) % NUM, 0, (xorValue>>16) % NUM, 0};
Errors :
On (xorValue>>16) % NUM
error: non-constant-expression cannot be narrowed from type 'unsigned long' to 'char' in initializer list
insert an explicit cast to silence this issue
Thank you
Consider the following code:
#include <complex>
int main()
{
unsigned u = 1u;
auto result = static_cast<std::complex<int>>(u);
return 0;
}
Compiling with
g++ -std=c++11 -Werror -Wsign-conversion -o a.out source_file.cpp
Causes compile error
source_file.cpp: In function ‘int main()’:
source_file.cpp:8:51: error: conversion to ‘int’ from ‘unsigned int’ may change the sign of the result [-Werror=sign-conversion]
auto result = static_cast<std::complex<int>>(u);
^
clang reports a similar error
source_file.cpp:6:50: error: implicit conversion changes signedness: 'unsigned int' to 'const value_type' (aka 'const int') [-Werror,-Wsign-conversion]
auto result = static_cast<std::complex<int>>(u);
~~~~~~~~~~~ ^
The error does not make much sense at first sight, what am I missing?
You get a conversion warning not from the cast, but from inside construction of std::complex.
To 'fix' your example you should instead do:
auto result = std::complex<int>{static_cast<int>(u)};