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.
Related
I know this is a noob question bit I am not familiar with c++ .
My understanding is that arduino code compiles in c++ and this is what causes the problem in compiling.
The code below will compile fine in codeblocks and will run correctly , however if I use the same code without any modifications then it will produce an error at compile time.
heres is the .ino file
#include "MCS6502.h"
int8_t ram [65535];
//////CALL BACK FUNCTION ///////////////////////////////////////////////
uint8_t readBytesFunction(uint16_t add) {
uint8_t tc = 5;
tc = ram[add];
return tc;
}
//////CALL BACK FUNCTION ///////////////////////////////////////////////
void writeBytesFunction(uint16_t add,uint8_t bb) {
}
void setup()
{
Serial.begin(115200);
Serial.println();
///CODE BELOW WILL COMPILE AND RUN IN CODEBLOCKS BUT WILL NOT COMPILE IN ARDUINO
/////////////////////////////////////////////////////////////////////
MCS6502ExecutionContext context;
MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL); // Final param is optional conte>
MCS6502Reset(&context);
MCS6502Tick(&context); //use timings
MCS6502ExecNext(&context); //as fast as possible
}
these are the errors after compiling in arduino for esp32
MCS6502.ino: In function 'void setup()':
wahid_MCS6502:22:27: error: invalid conversion from 'uint8_t (*)(uint16_t)' {aka 'unsigned char (*)(short unsigned int)'} to 'MCS6502DataReadByteFunction' {aka 'unsigned char (*)(short unsigned int, void*)'} [-fpermissive]
MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL); // Final param is optional conte>
^~~~~~~~~~~~~~~~~
MCS6502.h:91:33: note: initializing argument 2 of 'void MCS6502Init(MCS6502ExecutionContext*, MCS6502DataReadByteFunction, MCS6502DataWriteByteFunction, void*)'
MCS6502DataReadByteFunction readByteFn,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
MCS6502:22:46: error: invalid conversion from 'void (*)(uint16_t, uint8_t)' {aka 'void (*)(short unsigned int, unsigned char)'} to 'MCS6502DataWriteByteFunction' {aka 'void (*)(short unsigned int, unsigned char, void*)'} [-fpermissive]
MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL); // Final param is optional conte>
^~~~~~~~~~~~~~~~~~
MCS6502.h:92:34: note: initializing argument 3 of 'void MCS6502Init(MCS6502ExecutionContext*, MCS6502DataReadByteFunction, MCS6502DataWriteByteFunction, void*)'
MCS6502DataWriteByteFunction writeByteFn,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
exit status 1
invalid conversion from 'uint8_t (*)(uint16_t)' {aka 'unsigned char (*)(short unsigned int)'} to 'MCS6502DataReadByteFunction' {aka 'unsigned char (*)(short unsigned int, void*)'} [-fpermissive]
what do i need to do it compiles in arduino ??
apologies if some details are missing from this question but its my 1st ever time asking a question here.
many thanks
I'm guessing that you are using this library?
Looking at the signatures of the callback functions both require a final void* parameter which your callbacks are missing.
You need:
uint8_t readBytesFunction(uint16_t add, void*) {
uint8_t tc = 5;
tc = ram[add];
return tc;
}
void writeBytesFunction(uint16_t add,uint8_t bb, void*) {
}
While I'm compiling this simple program in GCC compiler I'm getting this error:-
warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int’ [-Wformat=]*
#include <stdio.h>
int main()
{
printf("Pointer\n");
printf("*******\n\n");
int i=3;
printf("Address of Variable i : %u",&i);
printf("Value stored in Variable i : %d\n",i);
printf("Value stored in Variable i : %d\n",*(&i));
return 0;
}
Even without any extra option, gcc (9.3.0) shows a detailed warning message
a.cpp: In function 'int main()':
a.cpp:7:38: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'int*' [-Wformat=]
7 | printf("Address of Variable i : %u",&i);
| ~^ ~~
| | |
| | int*
| unsigned int
| %n
So there's a mismatch between the format %u (unsigned int) and the argument &i (pointer).
Looking at printf Conversion specifier
u converts an unsigned integer into decimal representation dddd.
...
p writes an implementation defined character sequence defining a pointer.
The proper format in this case would be %p for a pointer argument &i
printf("Address of Variable i : %p", &i);
I'm trying to implement my own swap function for array, but it seems to have conversion problem.
And I do not have a clue.
Forgive me if this question is too stupid.
Here is the source code:
x_quiz3.h
#include<array>
using namespace std;
void swap_arr_element(array<int,5> &arr, int index1, int index2){
int temp{arr.at(index1)};
arr.at(index1) = arr.at(index2);
arr.at(index2) = temp;
}
void start_x_quiz3(){
array arr{1,2,4,3,5};
swap_arr_element(arr, 2, 3);
for (auto &i : arr){
cout << i << " ";
}
}
main.cpp:
#include <iostream>
#include "x_quiz3.h"
int main()
{
start_x_quiz3();
return 0;
}
error message:
||=== Build: Debug in chapter6 (compiler: GNU GCC Compiler) ===|
/home/lewisluk/CodeBlocksProjects/tutorials/quizs/chapter6/x_quiz3.h||In function ‘void swap_arr_element(std::array<int, 5>&, int, int)’:|
/home/lewisluk/CodeBlocksProjects/tutorials/quizs/chapter6/x_quiz3.h|8|error: conversion to ‘std::array<int, 5>::size_type {aka long unsigned int}’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]|
/home/lewisluk/CodeBlocksProjects/tutorials/quizs/chapter6/x_quiz3.h|9|error: conversion to ‘std::array<int, 5>::size_type {aka long unsigned int}’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]|
/home/lewisluk/CodeBlocksProjects/tutorials/quizs/chapter6/x_quiz3.h|9|error: conversion to ‘std::array<int, 5>::size_type {aka long unsigned int}’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]|
/home/lewisluk/CodeBlocksProjects/tutorials/quizs/chapter6/x_quiz3.h|10|error: conversion to ‘std::array<int, 5>::size_type {aka long unsigned int}’ from ‘int’ may change the sign of the result [-Werror=sign-conversion]|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
The argument to the at function is size_type, which is an unsigned type.
The index arguments to your swap function are int which is a signed type.
The compiler says that it can not safely convert from a signed type to an unsigned type (which it can't, think about what happens if you provide negative indexes).
The simple solution is to make the swap function index arguments unsigned as well, preferably using the size_t type:
void swap_arr_element(array<int,5> &arr, size_t index1, size_t index2){ ... }
I'm trying to exponentiate large bit numbers using the gmp library mpz_ui_pow_ui() but the mpz_class values that I pass in give me the error:
error: invalid conversion from ‘mpz_ptr {aka __mpz_struct*}’ to ‘long unsigned int’ [-fpermissive]
mpz_ui_pow_ui(cipher.get_mpz_t(), pTxt.get_mpz_t(), e.get_mpz_t());
All the values being passed in are mpz_class types. Why am I getting the error, and how can I make it work?
https://gmplib.org/manual/Integer-Exponentiation.html
— Function: void mpz_ui_pow_ui (mpz_t rop, unsigned long int base, unsigned long int exp)
The function takes unsigned long, not mpz_t.
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]