> when i checked a lot of big project's source codes, I have found them
> replacing basic funtion names with new function names, and
> sometimes with a
> new way of functioning for example:
>
> free() -> OPENSSL_free()
> malloc() -> gnew(type, number of blocks)
>
> how can this be useful ?, does it have a thing to do with
> portability ?, and
> if not what's the difference in functionality ?
For libraries, it can have some conveniences, like:
----------
#define g_new(struct_type, n_structs) \
((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize)
(n_structs))))
----------
So you'll use it like
----------
struct foo { ... };
struct foo* many_foos = g_new(foo, 10);
----------
instead of
----------
many_foos = malloc(sizeof(foo) * 10);
or
many_foos = calloc(sizeof(foo), 10);
----------
Using macros, you can also include debuggin info, like:
---------
#ifdef DEBUG_INFO
#define my_malloc(n) \
(alloc_bytes++,malloc(n))
#else
#define my_malloc malloc
#endif
---------
or
---------
#ifdef DEBUG_INFO
#define my_free my_debugged_free
#else
#define my_free free
#endif
void my_debugged_free(void* p)
{
if (!p) {
puts("Hey you stupid, your're trying to free(NULL)!");
abort();
} else
free(p);
}
---------
So it's easy to track programming errors.
Daniel K. O.
It's OK to be ignorant; it's not OK to play stupid.
http://www.catb.org/~esr/faqs/smart-questions.html
|