home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] 'C' used in drivers question?

  • Subject: Re: [OCLUG-Tech] 'C' used in drivers question?
  • From: Martin Hicks <mort [ at ] bork [ dot ] org>
  • Date: Fri, 7 Dec 2007 12:27:04 -0500
On Fri, Dec 07, 2007 at 12:09:56PM -0500, William Case wrote:
> Hi;
> 
> I am patiently reading the O'Reily "Linux Device Drivers" and have come
> across the following line (and several like it):
> 
> int (*open) (struct inode *, struct file *)
> 
> I can interpret most of the line except the 'inode *' and 'file *'.  I
> have never seen the asterisk in C used in this fashion.  What does it
> mean?

this is a pointer to a funtion (*open).  This function takes two
arguments:

a pointer to a "struct inode"
a pointer to a "struct file"

The function returns and int.

Perhaps they confused you because they don't actually name the two
function arguments.  Something like this is likely found elsewhere:

int real_open(struct inode *inode, struct file *file);

And somewhere else in the code they would assign the real function to
the pointer:

 open = real_open;


This is how linux achieves much of its abstraction: using function
pointers.

mh

-- 
Martin Hicks || mort [ at ] bork [ dot ] org || PGP/GnuPG: 0x4C7F2BEE