I wrote by mistake a not-void function that does not return anything. I didn't get warning or some error. I have copied the same function in a different environment (this environment has an old version of Ubuntu and the compiler belongs to an older ARM Poky family-GNU GCC 5.x ARM poky, before was FAMILLY GNU GCC 6.x ARM OE) and I got sgm fault.
I know that a not-void function has an undetermined behavior, but how I can prove that the compilers influences this?
Here is a simplification of my function:
std::shared_ptr<int> get_ptr()
{
std::shared_ptr<int> p = nullptr; //missing return
}
int main () {
std::shared_ptr<int> a = get_ptr(); //what is actually initialize with?
if (nullptr == a)
std::cout << "Is working \n"<< std::endl;
else std::cout << *get_ptr();
return 0;
}
Know somebody explain me what is happening behind the scenes? Will help me a lot any information.
Aucun commentaire:
Enregistrer un commentaire