3 gcc LANG mintty bash GNU C LANGC
3 gcc のエラーメッセージ • 環境変数LANGを設定すると言語が変わる mintty + bash + GNU C $ LANG=C gcc error 1. c: In function 'main': error 1. c: 7: 3: error: expected '; ' before 'printf' printf("worldn"); ^ mintty + bash + GNU C $ LANG=ja_JP. UTF-8 gcc error 1. c: 関数 ‘main’ 内: error 1. c: 7: 3: エラー: expected ‘; ’ before ‘printf’ printf("worldn"); ^ ロケール(locale)と呼ばれる 多言語化の仕組み JM: locale (7)
4 mintty の locale の設定 • mintty左上のアイコンからoption→Text ここに Locale: ja_JP Cahaacter set: UTF-8 を設定して「OK」しておく
6 ブロック開始終端の不整合 • 「{」が1つ多い 4 5 6 7 8 9 10 error 2_1. c mintty + bash + GNU C int main() { { printf("hello, worldn"); $ gcc error 2_1. c: 関数 ‘main’ 内: error 2_1. c: 10: 1: エラー: expected declaration or statement at end of input } ^ return EXIT_SUCCESS; } 「}」が1つ足らない状態で、ファイルの終端(入力の終端)に達している。
講義資料 第 4週pp. 42 -44. , 第 9週p. 6. , 教科書p. 171. call by pointer (ポインタ渡し) • 呼び出し元の変数の内容を変更したい場合 swapi. c 訂正 2014 -07 -11 誤: swap 正: swapi void swapi(int *a, int *b) { int c; c = *a; *a = *b; *b = c; } swapi_test. c int a, b; fprintf(stderr, "a = ? "); scanf("%d", &a); fprintf(stderr, "b = ? "); scanf("%d", &b); swapi(&a, &b); void swapi(int *a, int *b); 関数 *a と *b の値を入れ替える printf("a = %dn", a); printf("b = %dn", b); 10
17 ポインタを用いた文字列操作の例 • strlen 関数の大まかな仕組み strlen_with_idx. c size_t strlen(const char *s) { size_t len = 0; while (s[len] != '