Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active May 2, 2016 10:50
Show Gist options
  • Save cocodrips/82388208de63622ec74973383df65f49 to your computer and use it in GitHub Desktop.
Save cocodrips/82388208de63622ec74973383df65f49 to your computer and use it in GitHub Desktop.
脳みそ整理用
#include "stdafx.h"
#include <iostream>
struct Klass {
int value;
};
struct Data {
int value;
Klass *klass;
Data () {
value = 1;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Data *data = new Data();
size_t ptr_size = sizeof(data->klass); // 4
size_t int_size = sizeof(data->value); // 4
size_t data_size = sizeof(*data); // 8
void* address = (void*) &(((Data*)0)->klass);
Data* zeroData = (Data*)0;
void* offset = (void*) &(zeroData->klass);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment