's WiLiKi

g++でgdbmを使うと error: non-local function uses anonymous type




現象

g++ にて gdbm を使おうとすると、下記のエラーになる

$ cat c.cpp
#include <gdbm.h>

void foo(GDBM_FILE *p)
{
}

$ g++ c.cpp
c.cpp:3: error: non-local function ‘void foo(<anonymous struct>**)’ uses anonymous type

環境

$ g++ --version
g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat /etc/redhat-release
CentOS release 6.2 (Final)

原因

C++ では、無名構造体へのポインタは使えないため。gdbm-1.10にて修正された模様。

$ grep GDBM_FILE /usr/include/gdbm.h
typedef struct {int dummy[10];} *GDBM_FILE;

$ grep GDBM_FILE gdbm-1.10/src/gdbm.h
typedef struct gdbm_file_info *GDBM_FILE;

対処

--- /usr/include/gdbm.h 2010-11-11 17:21:30.000000000 +0900
+++ gdbm.h      2012-06-03 21:30:43.066350424 +0900
@@ -60,7 +60,8 @@


 /* The file information header. This is good enough for most applications. */
-typedef struct {int dummy[10];} *GDBM_FILE;
+struct gdbm_dummy_info { int dummy[10]; };
+typedef struct gdb_dummy_info *GDBM_FILE;

 /* Determine if the C(++) compiler requires complete function prototype  */
 #ifndef __P

リンク

-Bug 668178 - gcc 4.5 warning









[トップ] / [最近の更新] [一覧] [編集履歴] [RSS]
Last modified : 2012/06/03 21:33:14 JST
WiLiKi 0.5.3 running on Gauche 0.9.4