Is there any memory overhead for each structure in clang? Typically, the size of a structure is just the total size of all its members. But this is not like clang:
#include <iostream>
using namespace std;
struct Obj {
int x;
int y;
};
int main() {
int a = 42;
int b = 43;
Obj obj = {100, 101};
int c = 44;
cout << *(&a - 0) << endl;
cout << *(&a - 1) << endl;
cout << *(&a - 2) << endl;
cout << *(&a - 3) << endl;
cout << *(&a - 4) << endl;
cout << *(&a - 5) << endl;
return 0;
}
I compiled with clang++ program.cpp, without optimization. Version:
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
The memory location in (&a - 2)seems not to be used at all. I entered the following code between the declaration int aand int b:
*(&a - 2) = -1234;
This will later print -1234instead of the garbage value on *(&a - 2), indicating that clang did not write this value after creation Obj obj, which makes me wonder why the clang reserved it in the first place.
gcc -. -, , , gcc . , gcc , c b, :
cout << *(&a + 0) << endl;
cout << *(&a + 1) << endl;
cout << *(&a + 2) << endl;
cout << *(&a + 3) << endl;
cout << *(&a + 4) << endl;
g++ program.cpp. :
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
, C. 64- Linux Mint 17.1. - , , 4 ?