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.
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 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*) {
}
Edit:
Resolved, can't accept my answer for two days
I'm using PlatformIO to program a Arduino Nano to write a message to an OLED display.
I'm calling a function printWeight:
void printWeight(
float weight,
uint8_t scale=3,
uint8_t numbd=3,
uint8_t numad=2,
bool kg=false,
const char* description_text_line="Weight:",
uint8_t width_per_character=5+1,
uint8_t height_per_line=7+3
){
...
The function is centering the text by calculating the leading space leading_space and calls itself with a smaller scale (scale-1) if the message doesn't fit on the screen:
if(leading_space < 0){
printWeight(weight, scale-1, numbd, numad, description_text_line,
width_per_character, height_per_line);
return;
}
The code compiles and runs fine. However I'm getting the following warning that I don't know how to resolve:
src/main.cpp: In function 'void printWeight(float, uint8_t, uint8_t, uint8_t, bool, const char*, uint8_t, uint8_t)':
src/main.cpp:138:53: warning: invalid conversion from 'uint8_t {aka unsigned char}' to 'const char*' [-fpermissive]
width_per_character, height_per_line);
^
src/main.cpp:93:6: note: initializing argument 6 of 'void printWeight(float, uint8_t, uint8_t, uint8_t, bool, const char*, uint8_t, uint8_t)'
void printWeight(
^
How do I get rid of this warning?
Missing parameter...
Thanks to the ones commenting.
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 am trying to cast TracedValue<uint32_t> m_bytesInFlight to uint32_t but I get the following error
error: cannot convert ‘ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >’ to ‘uint32_t {aka unsigned int}
Function prototype and variable declarations are
uint32_t UnAckDCount (void) const;
TracedValue<uint32_t> m_bytesInFlight {0}; //!< Bytes in flight
Here i am calling the function
uint32_t
TcpSocketBase::UnAckDCount () const
{
return m_tcb->m_highTxMark - (uint32_t) m_tcb->m_bytesInFlight;
}
Please suggest some method so that I can execute the return statement to get the result. Thanks in advance
Changing m_tcb->m_highTxMark to m_tcb->m_highTxMark.Get().GetValue() should work.
Seeing the compiler error, it's easy to figure out that variable m_highTxMark is of type ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >. I checked the documentation of ns3::TracedValue and ns3::SequenceNumber, they both have getter functions Get() and GetValue() respectively.
See:
https://www.nsnam.org/doxygen/classns3_1_1_traced_value.html
https://www.nsnam.org/doxygen/classns3_1_1_sequence_number.html