Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("Hello World!\n");
return EXIT_SUCCESS;
}
@koturn
koturn / macro.h
Last active December 13, 2015 17:29
/*!
* @brief マクロのみを提供するヘッダファイル
*
* 強力なマクロを複数用意している。<br>
* 関数のように扱うことができない(文法拡張的な)マクロについては、<br>
* マクロ名の先頭に"$"を付けている。
*
* @author koturn 0;
* @file macro.h
* @version 1.15.0.0
@koturn
koturn / lambda.c
Last active April 15, 2022 02:34
C言語におけるラムダを関数マクロで実現したものです。 GNU拡張文法(複文の式化、関数内の関数定義)を用いているので、gccでしか用いることができません。 また、トップレベルで用いることも不可能です。 C++でもコンパイルエラーにならないように、C++0xのラムダに変換するようにしています。 利便性を考え、ある程度の省略表記を許すようにしています。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*!
* @brief GNU拡張機能を用いたラムダ関数を実現するマクロ
*
* gccもしくはC++0x対応コンパイラでのみコンパイル可能<br>
* トップレベルで用いることはできない
@koturn
koturn / shebang.c
Created May 18, 2013 20:29
C言語のソースファイルを実行可能にした場合、コンパイル&実行できるように細工したもの。
#if 0
src=$0
exe=${src%.*}
gcc -s -O3 -pipe -Wall -Wextra -o $exe $src && $exe $@
exit
#endif
#include <stdio.h>
#include <stdlib.h>
@koturn
koturn / template.c
Last active December 17, 2015 14:59
C言語ソースのテンプレート
#if 0
############################################################
### If you execute this source file as a shell-script, ###
### you can compile this source file. ###
############################################################
gcc -pipe -O3 -s -Wall -Wextra $0 $@ -o ${0%.*}
if [ $? -ne 0 ]; then
echo '!!!Compile error!!!'
fi
exit
@koturn
koturn / bsearch.c
Created June 10, 2013 22:23
bsearch()関数で文字列を探すサンプルコードです。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Macros for restrict-qualifier under various environmets
#if _MSC_VER >= 1400 // In Visual C++ (after Visual C++ 2005),
# define restrict __restrict // 'restrict' and '__inline__' aren't available
# define __restrict__ __restrict // but '__restrict' is.
#elif __cplusplus // In language C++ (but not Visual C++),
@koturn
koturn / .vimrc
Last active December 19, 2015 03:39
NeoBundleにより、インサートモード時にプラグインの遅延ローディングを行った場合における、 挿入モード時のステータスラインの色の自動変更が行われない問題の解決方法。 WIndows7のvim/gvim, Windows7-Cygwin上のvimでこの問題が起こっていた。 私はWindowsユーザであるため、他の環境で起こる問題であるかどうかは不明。 挿入モード時のステータスラインの色変更について: https://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-color#color-insertmode
let $DOTVIM = $HOME . '/.vim'
if has('vim_starting')
set runtimepath+=$DOTVIM/bundle/neobundle.vim
endif
call neobundle#rc(expand('$DOTVIM/bundle/'))
NeoBundle 'Shougo/neobundle.vim'
NeoBundleLazy 'Shougo/neocomplete.vim', {'autoload' : {'insert' : 1}}
augroup MyAutoCmd
autocmd!
@koturn
koturn / .vimrc
Created June 29, 2013 20:16
NeoBundleのautoloadで、インサートモード時にプラグインを読み込む場合に、問題が発生する最小コードです。インサートモード時に、ステータスラインのカラーを変更する処理がうまく動作しなくなります。
let $DOTVIM = $HOME . '/.vim'
if has('vim_starting')
set runtimepath+=$DOTVIM/bundle/neobundle.vim
endif
call neobundle#rc(expand('$DOTVIM/bundle/'))
NeoBundle 'Shougo/neobundle.vim'
NeoBundleLazy 'Shougo/neocomplete.vim',
\ {'autoload' : {'insert' : 1}
\}
@koturn
koturn / vim-article-20130704.md
Created July 4, 2013 19:04
Vimに関する個人的なメモのようなもの

NeoBundleのインサートモード時遅延読み込みの注意点

NeoBundleでインサートモード時に遅延読み込みすると、インサートモード時に
ステータスラインの色を変更するというよくある設定が うまくいかないということを
Twitterで呟いたところ、暗黒美夢王さんから返答がきたので、そのことについて
書いてみようかと。

挿入モードでステータスラインの色を変更する

@koturn
koturn / binLiteral.c
Created October 13, 2014 16:26
Binary literal macro
#include <stdio.h>
#include <stdlib.h>
#define BIN_LITERAL_8(bin) \
( \
((0x0000000f & (0x ## bin)) != 0 ? 1 : 0) | \
((0x0000000f & (0x ## bin >> 4)) != 0 ? (1 << 1) : 0) | \
((0x0000000f & (0x ## bin >> 8)) != 0 ? (1 << 2) : 0) | \
((0x0000000f & (0x ## bin >> 12)) != 0 ? (1 << 3) : 0) | \
((0x0000000f & (0x ## bin >> 16)) != 0 ? (1 << 4) : 0) | \