Skip to content

Instantly share code, notes, and snippets.

@gicmo
Last active August 29, 2015 13:56
Show Gist options
  • Save gicmo/8958152 to your computer and use it in GitHub Desktop.
Save gicmo/8958152 to your computer and use it in GitHub Desktop.
shared pointer null dereference text
#include <iostream>
#include <memory>
int
main(int argc, char **argv)
{
std::shared_ptr<int> ptr;
try {
std::cout << *ptr << std::endl;
} catch (...) {
std::cout << "Exception!" << std::endl;
}
return 0;
}
//% clang -Wall -std=c++11 -stdlib=libc++ -lc++ -o shrd_ptr shrd_ptr.cc
// --> zsh: segmentation fault ./shrd_ptr
//% gcc -Wall -std=c++11 -lstdc++ -o shrd_ptr_gcc shrd_ptr.cc
// zsh: segmentation fault ./shrd_ptr_gcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment