[ENet-discuss] 1.0 imminent - any requests?

Brian Hook hook_l at pyrogon.com
Tue Dec 23 12:01:21 PST 2003


My belief is that an API should have a "simple default" initializer 
that does the standard stuff you'd expect, and then an enhanced one 
that allows the user to specify specific parameters.

For example:

int api_initialize( void );
int api_initialize_ex( const api_callbacks *cb );

typedef void *(*API_ALLOC)( size_t size );
typedef void  (*API_FREE)( void *p );

typedef struct
{
   int cb_size;
   API_ALLOC cb_alloc;
   API_FREE  cb_free;
  /* whatever else is necessary */
} api_callbacks;

The "cb_size" allows you to rev this later without breaking binary 
compatibility.

The default api_initialize would be something like:

void api_initialize( void )
{
   api_callbacks cb;

   cb.cb_size  = sizeof( cb );
   cb.cb_alloc = __api_default_alloc;
   cb.cb_free  = __api_default_free;
 
   return api_initialize_ex( &cb );
}

You'll probably want to explicitly define the calling convention if 
possible to avoid weird problems if the library is compiled for cdecl 
but someone has their compiler default to fastcall or stdcall or some 
other convention.

Brian





More information about the ENet-discuss mailing list