yaotti's diary

Software is Eating the World

c

Cでqueue

c

添削してもらいました: yaotti's gist: 87671 — Gist ちょっとCを書きたくなったので書いてみた. いくつかwarningが出るが,原因がわからない. #include <stdio.h> #include <stdlib.h> /* queue structure */ typedef struct { struct atom_t *head; struct atom_t *tail; } </stdlib.h></stdio.h>…

ソースコード解析にEmacsとcscope

c

twitterでEmacs+cscopeがいいと聞いたので入れてみた。 sudo port install cscope cd <解析したいコード群のあるディレクトリ> cscope -qRこれでokEmacsから使うにはこれをロードパスの通ったところに置き、.emacs(or .emacs.el)に (require 'xcscope) と追…

標準ライブラリ

cの標準ライブラリのソースを読んでみる。 wikiでページ作るかな。まずはincludeのないcdef.hから順番に。

インクリメント

c

#include <stdio.h> #include <stdlib.h> main(void) { int c, i, j; int *buf; buf = (int *) malloc(sizeof(int)*5); for (i=0; i<5; ++i) buf[i] = i; j = 0; while (j < i) { printf("j: %d ", j); printf("%d: %d\n", j, buf[j++]); /* ここ */ } } 実行結果 j: 0 1: 0 j: </stdlib.h></stdio.h>…

この2つの違い

c ?

char tmp1[10]; char *tmp2 = malloc(10); tmp1は長さMAXNUM(cは1つ1バイトなのでMAXNUMバイト)の配列 tmp2はMAXNUMバイトの領域を指すポインタ printf("%d\n", sizeof(tmp1)); printf("%d\n", sizeof(*tmp2)); 結果は前者は10、後者は1。 tmp2はまだ領域を…

emacsで簡単に関数リファレンスを見る

1. http://www.gnu.org/software/libc/manual/ の一番下のTexinfoをダウンロード&解凍(tar -zxvf libc-texti.tar.gz) (libc = Linux C Library) 2. makeinfo libc-texinfo 3. できたファイルを~/infoなどに置き、以下を.emacsに追加 (require 'info) (setq I…

C言語のポインタ

c

ポインタ理解しようとがんばってます。 以下がなぜかエラー(bus error)になる。 #include <stdio.h> main(int argc, char *argv[]) { int a[10]; int *p; a[0] = 1; *p = 1; /* pの指す先に1を指定、なはず */ //p = 1; /* これはアドレスとして1を指定するのでおかし</stdio.h>…

K&R読み始めました

c k&r

カーニハン&リッチーのプログラミング言語Cを読み始めた。 プログラミング言語C 第2版 ANSI規格準拠作者: B.W.カーニハン,D.M.リッチー,石田晴久出版社/メーカー: 共立出版発売日: 1989/06/15メディア: 単行本購入: 24人 クリック: 606回この商品を含むブロ…