clangが親切だった件
サークルに顔を出した。そこで(紆余曲折の末)たらい回し関数の話になった。
もう時間が遅かったので、そこそこで切り上げて家へ帰ってから改めて、ということに。とりあえずCで書いてみる。
#include <stdio.h> long tarai(long x, long y, long z) { return (x <= y) ? y : tarai( tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y) ); } int main(int argc, char* argv[]) { printf("%d\n", tarai(19, 8, 0)); return 0; }
…さてコンパイルしてみる。ここでもclangを使ってみた。
$ clang tarai_c.c
するとこんな警告が出た。
tarai_c.c:15:14: warning: conversion specifies type 'int' but the argument has type 'long' [-Wformat] printf("%d\n", tarai(19, 8, 0)); ~^ ~~~~~~~~~~~~~~~
なかなかわかりやすい警告表示だ。ちょっと感動した。
ちなみにgccでコンパイルするとこんな感じ。
$ gcc tarai_c.c tarai_c.c: In function ‘main’: tarai_c.c:15: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’