// co_112_551.c
// ##############################################################
// ##
// ## このプログラムはとっても危険かも知れません!!
// ##
// ## 実行中、作成した本人のPCが、かなり負荷がかかった後
// ## 勝手に電源が落ちました(熱暴走?)
// ## 実行される方は自己責任で。
// ##
// ##############################################################
#include <stdio.h>
#include <stdlib.h>
int check(void);
void make_code(int n);
int main(int argc, char *argv[])
{
int min_if;
int max_if;
int n;
// 初期値 = 1 で開始し、2倍してコンパイルを試していく
for (min_if = 1; min_if < 0x40000000; min_if *= 2) {
fprintf(stderr
, "testing %d", min_if
); make_code(min_if);
if (check()) { //error
break;
}
}
if (min_if >= 0x40000000) {
fprintf(stderr
, "%dまで試したがコンパイル出来た\n", 0x20000000); fprintf(stderr
, "(これ以上は当プログラムでは試せない)\n"); return 0;
}
// 挟みうちでコンパイルを試していく
max_if = min_if;
min_if /= 2;
while (1) {
n = (max_if + min_if) / 2;
make_code(n);
if (check()) { //error
max_if = n;
} else {
min_if = n;
}
if (max_if - min_if <= 1) {
break;
}
}
// 結果
printf("%d個までは大丈夫\n", min_if
); printf("%d個でコンパイルエラー\n", max_if
);
return 0;
}
// if ~ else を n 個作成
void make_code(int n)
{
FILE *fp;
int i;
fp
= fopen("test.c", "w"); fprintf(fp
, "int main(int argc, char *argv[])\n"); for (i = 2; i <= n; i++) {
fprintf(fp
, " } else if(argc == %d) {\n", i
); }
}
// make_code(); で生成された test.c がコンパイル出来るかテスト
int check(void)
{
int res;
res
= system("gcc -c -Wall test.c"); if (res == 0) {
}
return res;
}
// End of co_112_551.c
Ly8gY29fMTEyXzU1MS5jCi8vICMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCi8vICMjICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAovLyAjIyAg44GT44Gu44OX44Ot44Kw44Op44Og44Gv44Go44Gj44Gm44KC5Y2x6Zm644GL44KC55+l44KM44G+44Gb44KTISEgICAgICAgICAgICAKLy8gIyMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCi8vICMjICDlrp/ooYzkuK3jgIHkvZzmiJDjgZfjgZ/mnKzkurrjga5QQ+OBjOOAgeOBi+OBquOCiuiyoOiNt+OBjOOBi+OBi+OBo+OBn+W+jCAgICAKLy8gIyMgIOWLneaJi+OBq+mbu+a6kOOBjOiQveOBoeOBvuOBl+OBnyjnhrHmmrTotbDvvJ8pICAgICAgICAgICAgICAgICAgICAgICAgCi8vICMjICDlrp/ooYzjgZXjgozjgovmlrnjga/oh6rlt7Hosqzku7vjgafjgIIgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKLy8gIyMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCi8vICMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjCgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKaW50IGNoZWNrKHZvaWQpOwp2b2lkIG1ha2VfY29kZShpbnQgbik7CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBpbnQgbWluX2lmOwogICAgaW50IG1heF9pZjsKICAgIGludCBuOwoKICAgIC8vIOWIneacn+WApCA9IDEg44Gn6ZaL5aeL44GX44CBMuWAjeOBl+OBpuOCs+ODs+ODkeOCpOODq+OCkuippuOBl+OBpuOBhOOBjwogICAgZm9yIChtaW5faWYgPSAxOyBtaW5faWYgPCAweDQwMDAwMDAwOyBtaW5faWYgKj0gMikgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAidGVzdGluZyAlZCIsIG1pbl9pZik7CiAgICAgICAgbWFrZV9jb2RlKG1pbl9pZik7CiAgICAgICAgaWYgKGNoZWNrKCkpIHsgICAgICAgICAgLy9lcnJvcgogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZnByaW50ZihzdGRlcnIsICIuLi4g44Kz44Oz44OR44Kk44Or5oiQ5YqfXG4iKTsKICAgIH0KICAgIGlmIChtaW5faWYgPj0gMHg0MDAwMDAwMCkgewogICAgICAgIGZwcmludGYoc3RkZXJyLCAiJWTjgb7jgafoqabjgZfjgZ/jgYzjgrPjg7Pjg5HjgqTjg6vlh7rmnaXjgZ9cbiIsIDB4MjAwMDAwMDApOwogICAgICAgIGZwcmludGYoc3RkZXJyLCAiKOOBk+OCjOS7peS4iuOBr+W9k+ODl+ODreOCsOODqeODoOOBp+OBr+ippuOBm+OBquOBhClcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgLy8g5oyf44G/44GG44Gh44Gn44Kz44Oz44OR44Kk44Or44KS6Kmm44GX44Gm44GE44GPCiAgICBtYXhfaWYgPSBtaW5faWY7CiAgICBtaW5faWYgLz0gMjsKICAgIHdoaWxlICgxKSB7CiAgICAgICAgbiA9IChtYXhfaWYgKyBtaW5faWYpIC8gMjsKICAgICAgICBmcHJpbnRmKHN0ZGVyciwgInRlc3RpbmcgJWQiLCBuKTsKICAgICAgICBtYWtlX2NvZGUobik7CiAgICAgICAgaWYgKGNoZWNrKCkpIHsgICAgICAgICAgLy9lcnJvcgogICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIi4uLiDjgrPjg7Pjg5HjgqTjg6vlpLHmlZdcbiIpOwogICAgICAgICAgICBtYXhfaWYgPSBuOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGZwcmludGYoc3RkZXJyLCAiLi4uIOOCs+ODs+ODkeOCpOODq+aIkOWKn1xuIik7CiAgICAgICAgICAgIG1pbl9pZiA9IG47CiAgICAgICAgfQogICAgICAgIGlmIChtYXhfaWYgLSBtaW5faWYgPD0gMSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CgogICAgLy8g57WQ5p6cCiAgICB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