Page 1 of 1

C Struct

Posted: Sun Jun 29, 2003 5:47 pm
by Balroj
Hi,

I was taking a look at the linux kernel source, and find this struc:

Code: Select all

struct consw {
const char *(*con_startup)(void);
void (*con_init)(struct vc_data *, int);
void (*con_deinit)(struct vc_data *);
void (*con_clear)(struct vc_data *, int, int, int, int);
void (*con_putc)(struct vc_data *, int, int, int);
void (*con_putcs)(struct vc_data *,const unsigned short *,int ,int ,int);
void (*con_cursor)(struct vc_data *, int);
int (*con_scroll)(struct vc_data *, int, int, int, int);
.....
But i don't understand it well, void (*con_init)(struct vc_data *, int);i don't understand this. Can anyone please explain it? :)

thanks.

Re:C Struct

Posted: Sun Jun 29, 2003 6:10 pm
by anubis
Hi,
con_init is a function asscociated with console initialization.

vc_data is a structure containig the properties regarding the console.

using vc_data, con_init initializes the console. i am not sure what the other parameter(int) in con_init refer to...

Re:C Struct

Posted: Sun Jun 29, 2003 11:35 pm
by be
I think this is a function pointers, some pointer assigned to a function, and then this function called not by name, but by the pointer. ::) :)

Re:C Struct

Posted: Mon Jun 30, 2003 1:24 am
by TB
void (*con_init)(struct vc_data *, int);

Yes, it's pointer to a function with (struct vc_data *, int) as parameters.
So, you would do something like:
con_init = (address of the function) and then you can do things like con_init(&data, 123);

Re:C Struct

Posted: Mon Jun 30, 2003 1:47 am
by Pype.Clicker
basically, this technique provide something looking like polymorphism in C: you can define how a console is initialized by setting the right function as console.con_init=f and then call it with something like console_ptr->con_init(data,int)

Re:C Struct

Posted: Tue Jul 01, 2003 1:42 am
by df
good for dirvers / vfs interfaces etc