B
bahadir.balban
Hi,
In my programming I do something like,
struct my_struct {
int data1;
int data1;
static void (* const my_privatefunc1) (my_struct * this)
static void (* const my_privatefunc2) (my_struct * this)
}
// function definitions
static void my_privatefunc1(mystruct * this) { }
static void my_privatefunc2(mystruct * this) { }
And on initialisation I do:
struct my_struct x = {
0,
0,
my_privatefunc1,
my_privatefunc2
};
if I had an init function for this, I would best have one that
allocated, initialised and returned a new object from heap, i.e.
my_struct * xp = x_allocator_and_initialisor();
or if I want my object on the stack, I could have a loose init function
and a struct on stack, i.e.
my_struct x; x_initialisor(&x);
But, whatif I wanted a statically allocated object, yet initialised,
and client involved in neither setting values explicitly, nor
associating it with such an init function. i.e. if I could do;
my_struct x; x.init(); that would be nice, because I dont want to have
the loose practices above. But would it be possible to associate init()
with x like this, in the first place?
Cheers,
Bahadir
In my programming I do something like,
struct my_struct {
int data1;
int data1;
static void (* const my_privatefunc1) (my_struct * this)
static void (* const my_privatefunc2) (my_struct * this)
}
// function definitions
static void my_privatefunc1(mystruct * this) { }
static void my_privatefunc2(mystruct * this) { }
And on initialisation I do:
struct my_struct x = {
0,
0,
my_privatefunc1,
my_privatefunc2
};
if I had an init function for this, I would best have one that
allocated, initialised and returned a new object from heap, i.e.
my_struct * xp = x_allocator_and_initialisor();
or if I want my object on the stack, I could have a loose init function
and a struct on stack, i.e.
my_struct x; x_initialisor(&x);
But, whatif I wanted a statically allocated object, yet initialised,
and client involved in neither setting values explicitly, nor
associating it with such an init function. i.e. if I could do;
my_struct x; x.init(); that would be nice, because I dont want to have
the loose practices above. But would it be possible to associate init()
with x like this, in the first place?
Cheers,
Bahadir