I'm cross-compiling a program for a raspberry pi 3. Below is a minimal working example of something I've written that show's an issue I'm running into.
I'm trying to fill a struct and then return that struct from a function. Importantly, one of the members of the struct is a double, which is initialized from a string that is an integer.
#include <iostream>
#include <string>
struct Thing {
size_t a{};
double b{};
};
double fill_b(){
std::string s = "1234";
double b = std::stod(s);
std::cout << b << std::endl;
return b;
};
Thing get_thing(){
Thing thing;
thing.a = 1;
thing.b = fill_b();
std::cout << thing.b << std::endl;
return thing;
};
int main(){
Thing thing = get_thing();
std::cout << "A: " << thing.a << std::endl;
std::cout << "B: " << thing.b << std::endl;
}
When I run this, A is correct, but B is some random number, even though when it is set it is correct. Repeated runs give the same numbers. Also, compiling this and running on my host computer, an m1 mac, gives a correct result.
1234
1234
A: 1
B: 2.11371e-314
At first I thought that maybe the implicitly defined copy constructor is bad and changed Thing to this:
struct Thing {
size_t a;
double b;
Thing() : a(), b() {}
Thing(const Thing& other) : a(other.a), b(other.b) {}
};
And now I get this for output. Repeated runs produce the same numbers.
1234
1234
A: 1
B: -5.48613e+303
So that doesn't seem to be it. My guess is that I possibly setup my cross compiling toolchain incorrectly, but I don't know how to verify that.
Edit:
I don't know why I didn't think of this until now. I compiled this on the pi and that worked, so it definitely is the toolchain.