CaboChaのCインターフェイス のバックアップの現在との差分(No.1) - アールメカブ

アールメカブ


CaboChaのCインターフェイス のバックアップの現在との差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[Programming]]



cc -O2 `cabocha-config --cflags` cabochaTest.c -o cabochaTest `cabocha-config --libs`

$ ./example -f2 -O2
$ ./cabochaTest -f2 -O2

 #include <cabocha.h>
 #include <stdio.h>
 
 int main (int argc, char **argv) 
 {
   cabocha_t *c;
   char p[1024] = "太郎は次郎が持っている本を花子に渡した。";
 
   c = cabocha_new(argc, argv);
 
   printf ("argc = %d, INPUT: %s arg: %s\n", argc, p, *(argv+1));
   printf ("RESULT:\n%s", cabocha_sparse_tostr(c, p));
 
   cabocha_destroy(c);
    
   return 0;
 }


mapなどのSTLを使うつもりで,CPP ファイルにすると,キャストでうるさく文句を言われる.
 ...
 char p[] = "太郎は花子が持っている本を次郎に渡した。";
 cabocha_t *cabocha = cabocha_new(argc, argv);
 cabocha_tree_t *tree = 0;
 ...
 tree = cabocha_sparse_totree(cabocha, p) ;

 $ g++ -O2 `cabocha-config --cflags` cabocha3.cpp
                 -o cabocha3 `cabocha-config --libs`

 cabocha3.cpp:38: error: invalid conversion from
   ‘const cabocha_tree_t*’ to ‘cabocha_tree_t*’

しようがないのでキャストする
 tree = const_cast<cabocha_tree_t*> 
         (cabocha_sparse_totree(cabocha, p) );