typdef in iw_handler.h

2010-11-01 Thread Bond
I have used typedef in my C programs previously many times.
So it is not new to me

For example consider following typedef
struct var {
int data1;
int data2;
char data3;
};

typedef struct var newtype;
then we can use newtype instead of struct var.

Now see this
typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
  union iwreq_data *wrqu, char *extra);

above is line number 314 in include/net/iw_handler.h

I was not able to understand what is being typedef'd here?
-- 
http://vger.kernel.org/vger-lists.html

--
To unsubscribe from this list: send an email with
unsubscribe kernelnewbies to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: typdef in iw_handler.h

2010-11-01 Thread Darshan Ghumare
On Mon, Nov 1, 2010 at 2:24 PM, Bond jamesbond.2...@gmail.com wrote:

 I have used typedef in my C programs previously many times.
 So it is not new to me

 For example consider following typedef
 struct var {
int data1;
int data2;
char data3;
 };

 typedef struct var newtype;
 then we can use newtype instead of struct var.

 Now see this
 typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info
 *info,
  union iwreq_data *wrqu, char *extra);

 above is line number 314 in include/net/iw_handler.h

 I was not able to understand what is being typedef'd here?
 --
 http://vger.kernel.org/vger-lists.html

 --
 To unsubscribe from this list: send an email with
 unsubscribe kernelnewbies to ecar...@nl.linux.org
 Please read the FAQ at http://kernelnewbies.org/FAQ


http://publications.gbdirect.co.uk/c_book/chapter8/typedef.html

-- 
Darshan®


Re: typdef in iw_handler.h

2010-11-01 Thread Cunsuo Guo
2010/11/1 Bond jamesbond.2...@gmail.com

 I have used typedef in my C programs previously many times.
 So it is not new to me

 For example consider following typedef
 struct var {
    int data1;
    int data2;
    char data3;
 };

 typedef struct var newtype;
 then we can use newtype instead of struct var.

 Now see this
 typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info 
 *info,
                          union iwreq_data *wrqu, char *extra);

 above is line number 314 in include/net/iw_handler.h

 I was not able to understand what is being typedef'd here?

A type of 'function pointer' with four args and a int return value is declared.
With the code you cited, you can use the following code to declare a
function pointer:
iw_handler my_fun_ptr;

--
To unsubscribe from this list: send an email with
unsubscribe kernelnewbies to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: typdef in iw_handler.h

2010-11-01 Thread Tapas Mishra
On Mon, Nov 1, 2010 at 2:49 PM, Darshan Ghumare
darshan.ghum...@gmail.com wrote:


 http://publications.gbdirect.co.uk/c_book/chapter8/typedef.html

iw_handler is the type. For example:

int do_something(struct net_device *dev, struct iw_request_info *info,
union iwreq_data *wrqu, char *extra)
{
/* do stuff */
}

int do_something_else( same thing here )
{
/* more stuff */
}

iw_handler handlers[10];
handlers[0] = do_something;
handlers[1] = do_something_else;
... etc. ...

int choice = 4;
handlers[choice](dev, blah1, info_arg, iwreq_blah_arg, NULL);

This allows you to set up an array of functions that all take the same
arguments but do different things. You can then use a variable to
choose the function without caring what it does, and pass the same
arguments regardless of which function is being called.

--
To unsubscribe from this list: send an email with
unsubscribe kernelnewbies to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ