【お知らせ】プログラミング記事の投稿はQiitaに移行しました。

2012-06-11から1日間の記事一覧

C#でJITからコールバック

C#でJITからコールバックさせてみました。PythonのコードをC#に移植したものです。 using System; using System.Runtime.InteropServices; class Program { [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr VirtualAlloc(IntPtr lpA…

C#でJIT

PythonでやったJITをC#に移植しました。32bit専用です。 using System; using System.Runtime.InteropServices; class Program { [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, int f…

void*とオフセット

C++

第6回 コンパイラ実装会で出た話題です。以下のコードがエラーになります。なぜ? test.cpp #include <stdlib.h> int main(void) { void *p = malloc(100); *(void **)&p[10] = reinterpret_cast<void *>(free); return 0; } コンパイル結果 $ g++ test.cpp test.cpp: In funct</void></stdlib.h>…

関数のサイズ

第6回 コンパイラ実装会で出た話題です。関数のサイズを取ろうとしたら1になりました。なぜ? test.c #include <stdio.h> int main(void) { printf("%d\n", sizeof(putchar)); return 0; } 実行結果 $ gcc test.c $ ./a.exe 1int aへのポインタが&aであるように、putc</stdio.h>…