Shammer's Philosophy

My private adversaria

2010-06-01から1ヶ月間の記事一覧

JavaScriptで任意のHTML要素を取得する

Lispでソースコードを整形表示HTMLにするサンプルをソースコードをHTML表示用に整形するLISPver1.0 - Shammerismで作成しているが、やっぱりJavaScriptで書きたいと調べてみた。innerHTMLというのを使用すればできそうだ。【JavaScript】 要素を取得する: や…

C言語・変数の最大値を超えた場合は?

C

以下のように、宣言した変数の最大値を超えるような計算をした場合、その変数は最小値に戻るようだ。 #include <stdio.h> #include <limits.h> int main(int argc, char * args[]){ int value = INT_MAX; printf("value = %d\n", value); printf("value = value + 1\n"); value </limits.h></stdio.h>…

変数のサイズ判定

C

変数の最大値・最小値 - Shammerismでは、各型の最大値と最小値を確認するプログラムを書いてみたが、今度は使用するメモリ領域を確認するプログラム。 #include <stdio.h> int main(int argc, char * args[]){ printf("sizeof(char) = %u\n", (unsigned)sizeof(char)</stdio.h>…

C の static 変数

C

百聞は一見に如かず。やってみるべし。 #include <stdio.h> int g = 0; void static_test(){ static int x = 0; int y = 0; printf("Global Static Normal\n"); printf("====================\n"); printf("%6d %6d %6d\n", g++, x++, y++); printf("================</stdio.h>…

文字列の連結-snprintf_ver2

C

文字列の連結-snprintf_ver1 - Shammerismの問題を修正。 #include <stdio.h> #include <stdlib.h> #include <string.h> char * returnString(char * v){ char * prefix = "[RES]"; int length = strlen(prefix) + strlen(v) + 1;// 1 is for '\0' char * response = (char *)malloc(lengt</string.h></stdlib.h></stdio.h>…

文字列の連結-snprintf_ver1

C

文字列の連結 - Shammerismでいろいろ悩んでいたが、どうやらsnprintfを使用するのが一番よさそうだ。まず、snprintfを使用しない力技バージョン。 #include <stdio.h> #include <stdlib.h> #include <string.h> char * returnString(char * v){ char * response; response = (char *)mall</string.h></stdlib.h></stdio.h>…

Makefile デビュー

C

初めて書いてみました。 # Makefile CC=gcc CFLAG=-g all: clean build clean: -rm *.o build: hello.o $(CC) -o hello hello.cポイントは以下。 最初に書かれたアクションが実行される(上の例ではall) ハイフンを付けたアクションは、エラーになっても無視…

文字列を返す関数

C

文字列を返す関数を書いてみた。非常にシンプルな例だが。。。 #include <stdio.h> #include <stdlib.h> #include <string.h> char * returnString(char * v){ char * response; response = (char *)malloc(strlen(v)); strcpy(response, v); return response; } int main(int argc, char </string.h></stdlib.h></stdio.h>…

Lisp Condition Level 1

コンディション超入門 - Shammerismの続き。with-open-socket で試した。サンプルコードは以下のような感じで、意図的に同一ポートの Socket を Open してみる。 (defun open-http-server (listen-addr listen-port) (let ((host listen-addr) (port listen-…