Skip to content

Instantly share code, notes, and snippets.

/foo.cpp Secret

Created June 9, 2014 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bd0db5e4bcb307b70506 to your computer and use it in GitHub Desktop.
Save anonymous/bd0db5e4bcb307b70506 to your computer and use it in GitHub Desktop.
// Built with: clang++ -O3 -g -std=gnu++11 -stdlib=libc++ foo.cpp -o foo
#include <fstream>
#include <iostream>
#define PRINT_INFO(x) std::cout << "sizeof(" #x ")=" << sizeof(x) << ", offset=" << ((char*)(x*)&zero - (char*)&zero) << '\n'
int main()
{
std::ifstream zero("/dev/zero");
PRINT_INFO(std::ifstream);
PRINT_INFO(std::istream);
PRINT_INFO(std::ios);
PRINT_INFO(std::ios_base);
return zero.get();
}
# Built with Xcode 4.6's clang:
themac:~ jorgen$ ./foo
sizeof(std::ifstream)=448, offset=0
sizeof(std::istream)=168, offset=0
sizeof(std::ios)=152, offset=296
sizeof(std::ios_base)=136, offset=296
# Built with Xcode 5.1's clang:
themac:~ jorgen$ ./foo-modern
sizeof(std::ifstream)=576, offset=0
sizeof(std::istream)=168, offset=0
sizeof(std::ios)=152, offset=424
sizeof(std::ios_base)=136, offset=424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment