続マクロ

昨日のエントリの続きです.
だいぶ解決してきました.
というか,コメントをきちんと読めという話ですね.
再掲.

/* If 10*Accum + Digit_val is larger than the maximum value for Type,
   then don't update Accum and return false to indicate it would
   overflow.  Otherwise, set Accum to that new value and return true.
   Verify at compile-time that Type is Accum's type, and that Type is
   unsigned.  Accum must be an object, so that we can take its
   address.  Accum and Digit_val may be evaluated multiple times.

   The "Added check" below is not strictly required, but it causes GCC
   to return a nonzero exit status instead of merely a warning
   diagnostic, and that is more useful.  */

#define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val, Type)                \
  (                                                                     \
   (void) (&(Accum) == (Type *) NULL),  /* The type matches.  */        \
   verify_expr (! TYPE_SIGNED (Type)),  /* The type is unsigned.  */    \
   verify_expr (sizeof (Accum) == sizeof (Type)),  /* Added check.  */  \
   (((Type) -1 / 10 < (Accum)                                           \
     || (Type) ((Accum) * 10 + (Digit_val)) < (Accum))                  \
    ? false : (((Accum) = (Accum) * 10 + (Digit_val)), true))           \
  )

で,こんな風に使います.

size_t value = 0;
char c = '3';
if(!DECIMAL_DIGIT_ACCUMULATE(value, '3' - '0', size_t)) {
    ...
}

ほいで,マクロの1行目ですけど,コンパイル時に,warning を出すためだと解釈しました.
型の異なるポインタを比較すると,怒られますと.
でですね,最後の3項演算子の最初の式がいまいち理解できていません.
2つめは,オーバーフローしたら,1周しちゃって,Accum より小さくなっちゃうと.


1つめは,-1 を使用することで,unsigned なら最大値になり,...
あ,わかりました.Accum に 10 を乗じても大丈夫かどうかのチェックですね.


まとめとしては,C で,型を比較するための方法だったということでいいでしょうか?
つまり,ポインタを比較すればよいと.


手動デバッガみたいなこと(現在の変数の値をメモしたり)をしながら読んでいるので,なかなかすすまん.
あと,etags 様々.


ついでに,etags で,M-x find-tag / M-. する際,デフォルトでは,
case-insensitive で探してくれると思うのですが,これが余計なお世話.
解決策の1つは,以下を ~/.emacs へ記述.

;; make tags operations case-sensitive.
(setq tags-case-fold-search nil)

これで幸せになれます.