Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > GDBM prototype ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 25762 of 27343
Post > Topic >>

GDBM prototype magic.

by vshenoy <vikram.u.shenoy@[EMAIL PROTECTED] > Apr 21, 2008 at 12:35 AM

Hi Guys,

I was going through gdbm-1.8.3 source (http://ftp.gnu.org/gnu/gdbm/
gdbm-1.8.3.tar.gz) and found this strange thing : all the exposed
functions of gdbm work with GDBM_FILE pointer (which is returned by
gdbm_open), but in the implementation of gdbm functions (e.g.
gdbm_open in gdbmopen.c)work with a structure called gdbm_file_info.

Now GDBM_FILE is defined like this in gdbm.h an exposed header :

typedef struct { int dummy[10];} *GDBM_FILE;

but gdbm_file_info is a structure which is a lot bigger than this.

For e.g. in gdbm.h gdbm_open is defined as :

extern int gdbm_store __P((GDBM_FILE, datum, datum, int)); /* __P(x)
is x if it is standard C or C++ else _P(x) is () */

but in its definition it is like this :

int
gdbm_store (dbf, key, content, flags)
     gdbm_file_info *dbf;
     datum key;
     datum content;
     int flags;

I have these questions : (I searched previous archives of c.l.c, but
only found mention of typedef struct {int dummy[10];} *GDBM_FILE; in a
post called "What makes C _not_ a subset of C++, where it said that
this particular declaration is illegal in C++)

1. How does this sort of code compiles in standard C ? ( What function
prototype matching rule of C applies here ?) When I checked in the
generated Makefile there wasn't any special flags that were passed to
gcc.

2. Why was this done ? My first guess is because the author did not
want to expose the gdbm_file_info structure in gdbm.h so that he can
change it between different releases preserving compatibility (?) Also
to keep the external interface clean.

3. Is this safe ? Will it work in all the compilers and machines i.e.
is it ****table ?

Any help is appreciated.
 




 5 Posts in Topic:
GDBM prototype magic.
vshenoy <vikram.u.shen  2008-04-21 00:35:50 
Re: GDBM prototype magic.
WANG Cong <xiyou.wangc  2008-04-21 16:28:01 
Re: GDBM prototype magic.
Barry Schwarz <schwarz  2008-04-21 05:51:23 
Re: GDBM prototype magic.
vshenoy <vikram.u.shen  2008-04-21 08:23:19 
Re: GDBM prototype magic.
Barry Schwarz <schwarz  2008-04-21 17:32:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 21:52:36 CDT 2008.