[...]
static clc_slink mylist = CLC_SLIST_STATIC_INIT(0);
/* returns NULL on failure */
my_node* my_node_produce(...) {
my_node* const _this = ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
clc_slist_push(&mylist, malloc(sizeof(*_this)));
return _this;
}
_________________________________________________
Ouch! We need a cast for the code above to compile correctly; like this:
_________________________________
my_node* const _this =
(my_node*)clc_slist_push(&mylist, malloc(sizeof(*_this)));
_________________________________
Okay... We can have the 'clc_slist_push/init' functions return 'void*' in
order to do away with the casting; here is the "fresher/newer" proposed API:
_______________________________
typedef struct clc_slink_s clc_slink;
struct clc_slink_s {
clc_slink* nx;
};
CLC_SLIST_STATIC_INIT(...); /* static initialization */
void* clc_slist_init(...); /* dynamic initialization; returns NULL on
failure. */
void* clc_slist_push(...); /* push a link; returns NULL on failure. */
clc_slink* clc_slist_pop(...); /* pop a link */
_______________________________
Now, using that interface, the following code will work:
_______________________________
typedef struct my_node_s my_node;
struct my_node_s {
clc_slink slink;
[...];
};
static clc_slink mylist = CLC_SLIST_STATIC_INIT(0);
/* returns NULL on failure */
my_node* my_node_produce(...) {
my_node* const _this =
clc_slist_push(&mylist, malloc(sizeof(*_this)));
return _this;
}
_______________________________
We should keep in mind that the more features we add, the more we move away
from the minimalist nature of the original proposal... I am sure this LIFO
API can be realized. IMVHO, we need to try and maintain a fairly high-level
of patience before we get into an all out flame war here...
;^)