Re: GLIB_CHECK_VERSION (was: Glib rand() function)



On Mon, 21 Feb 2000, Derek Simkowiak wrote:

> > > > > if (GLIB_CHECK_VERSION (1, 3, 0))
> > > > > 	[...use g_rand()...]
> > > > > else
> > > > > 	[...use rand()...]
> > > > 
> > 
> > Oh, you meant code, not configure.in... this won't work at all, you
> > are going to get undefined symbol g_rand().
> 
> 	That should have read:
> #if (GLIB_CHECK_VERSION(1,3,0))
> 	[...use g_rand()...]
> #else
> 	[...use rand()...]
> #endif
> 
> 	...so the undef'd symbol error shouldn't happen.
> 
> > Just use rand(), when you put it in glib you can worry about
> > portability....
> 
> 	One of my goals in writing this data type is learning the Glib
> coding style and portability rules.  I.e., I've already named the struct
> "GSkipNode" and the functions g_yada_yada(), and am using all the Glib
> data types (gint, etc.) and functions (g_malloc(), etc.).
> 
> 	If I knew what the current 1.3 minor version was I could put the
> GLIB_CHECK_VERSION in there and I think it would be Appropriate and
> Correct.  Please correct me if I'm wrong (I really am trying to learn the 
> "correct" way to do it).

simply consider 1.3.0 not released, and put 1.3.1 in the version checks,
e.g. here are some compatibility defines i use in BSE:

#if !GLIB_CHECK_VERSION (1, 3, 1)
#define G_STRINGIFY(macro_or_string)    _G_STRINGIFY_INTERNAL (macro_or_string)
#define _G_STRINGIFY_INTERNAL(contents) #contents
typedef struct _GTrashStack GTrashStack;
struct _GTrashStack { GTrashStack *next; };
static inline void g_trash_stack_push (GTrashStack **stack_p, gpointer data_p)
{ GTrashStack *data = data_p; data->next = *stack_p; *stack_p = data; }
static inline gpointer g_trash_stack_pop (GTrashStack **stack_p)
{ GTrashStack *data; data = *stack_p; if (data)
  { *stack_p = data->next; data->next = NULL; } return data; }
static inline gpointer g_trash_stack_peek (GTrashStack **stack_p)
{ GTrashStack *data; data = *stack_p; return data; }
static inline guint g_trash_stack_height (GTrashStack **stack_p)
{ GTrashStack *data; guint i = 0; for (data = *stack_p; data; data = data->next)
  i++; return i; }
static inline gpointer
_bse_datalist_id_remove_no_notify (GData **datalist,
                                   GQuark  key_id)
{
  gpointer ret_data = g_datalist_id_get_data (datalist, key_id);
  g_datalist_id_remove_no_notify (datalist, key_id);
  return ret_data;
}
#define g_datalist_id_remove_no_notify _bse_datalist_id_remove_no_notify
#endif /* !GLIB_CHECK_VERSION (1, 3, 1) */

> 
> Thanks,
> Derek
> 

---
ciaoTJ




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]