Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created January 8, 2012 10:13
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 maraigue/1577913 to your computer and use it in GitHub Desktop.
Save maraigue/1577913 to your computer and use it in GitHub Desktop.
必要あって size_t hoge; (reinterpret_cast<int *>(hoge))++; 的なことをしたかったけどこの記法じゃ無理だったので
#include <iostream>
int main(void){
size_t hoge;
hoge = 0;
// 意図としてはこう書きたいんだけど無理
// (reinterpret_cast<int *>(hoge))++;
// でもここまで愚直に書くのも嫌なので
// hoge = reinterpret_cast<size_t>((reinterpret_cast<int *>(hoge)) + 1);
// こう書くことにした
(*(reinterpret_cast<int **>(&hoge)))++;
std::cout << hoge << std::endl; // 環境にもよるけど4とかになるはず
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment