C言語カルトクイズ

CUDAも飽きたのでC言語にしよう。


以下、コンパイルが通る/通らないを答えなさい

Q1

struct xx {
	struct yy {int a;};
};
struct yy yy;
int main(){}

Q2

struct xx {
	struct xx {int a;};
};
int main(){}

Q3

struct xx {
	int a;
};
int main(){
	struct xx {int b;};
}

Q4

struct xx {
	int a[sizeof(struct xx{int a;})];
};
int main(){}

Q5

struct xx {
	int (*a)(struct xx {int a;} x);
};
int main(){}

Q6

struct xx {
	int global;
};
int main(){
	struct xx *x = (struct xx {int local;}*)0;
	struct xx *y;

	return x->global + y->local;
}

Q7

struct xx {
	int global;
};
int main(){
	struct xx;
	struct xx *x = (struct xx {int local;}*)0;
	struct xx *y;

	return x->global + y->local;
}

あれ…理解できない…これ…よく見たら、Q6ってGCCの結果おかしいのじゃないか…

Q8

struct xx {
	int global;
};
int main(){
	struct xx a;
	struct xx *x = (struct xx {int local;}*)0;
	struct xx *y;

	return x->global + y->local;
}

宣言子無しと有りは型指定子の意味が変わってるのか…

Q9

struct xx {
	int global;
};
int main(){
	struct xx x = *(struct xx*)(struct xx {int local;}*)0,
		y = *(struct xx*)0;
}

Q10

struct xx {
	int global;
};
int main(){
	struct yy {
		union xx { int local; };
	};
	struct xx xx;
}

さて、みんなはいくつ答えられたかな??

  • 50%以下 → 運が悪い
  • 51%以上、60%以下 → C言語赤ちゃん
  • 61%以上、70%以下 → C言語幼稚園児
  • 71%以上、80%以下 → C言語小学生低学年
  • 81%以上、90%以下 → C言語小学4年生
  • 91%以上、99%以下 → ありえない!!すごいスコアだ!
  • 100% → 全問正解!Cコンパイラを作るべき!