Created
January 8, 2012 10:13
-
-
Save maraigue/1577913 to your computer and use it in GitHub Desktop.
必要あって size_t hoge; (reinterpret_cast<int *>(hoge))++; 的なことをしたかったけどこの記法じゃ無理だったので
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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