fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. cout << "sizeof(string): " << sizeof(string) << endl;
  7.  
  8. string sso{"hello"};
  9. cout << " SSO offset: " << (uintptr_t)sso.data() - (uintptr_t)&sso << endl;
  10.  
  11. string non_sso{"some very long heap-allocated string"};
  12. cout << "Non-SSO offset: " << (uintptr_t)non_sso.data() - (uintptr_t)&non_sso << endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
sizeof(string): 32
    SSO offset: 16
Non-SSO offset: 18446697534250739984