Do compilers guarantee that the structure generated by your code will place the variables in the exact order you declared them? And if not, can you give an example for how to do this on, say, your compiler?
I am having this problem:
Code:
struct something {
int a;
int b;
int c;
int d;
};
struct something s;
memset(&s, 0, sizeof(s));
int value = 22;
s.a = value;
if(memcmp(&s, &value, sizeof(int)) == 0) {
cout << "Indeed..." << endl;
}
else {
cout << "Afraid not..." << endl;
}
The output is always negative.
However, I found the value at offset + 8, and thus this printed positive:
Code:
if(memcmp(&s + 8, &value, sizeof(int)) == 0) {
cout << "Indeed..." << endl;
}
else {
cout << "Afraid not..." << endl;
}
How can I enforce the order of placement?