By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,345 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,345 IT Pros & Developers. It's quick & easy.

what the statement in a structure mean

P: n/a
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye

Nov 13 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a

raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye
It is a pointer to a function that accepts two arguments, one of type
SDS_UINT32 and the other a void pointer.

-kyle

Nov 13 '06 #2

P: n/a

raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye
Well, func is a pointer to a function taking SDS_UINT32 and void* as
arguements, and which returns void, baisucally it is a function
pointer.

Speaking about function pointers, i have read in many books that it is
helpful in anti-virus software, can anyone tell the exact usage that
makes it so special in anti-virus softwares???

Nov 13 '06 #3

P: n/a

kyle.tk wrote:
raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye

It is a pointer to a function that accepts two arguments, one of type
SDS_UINT32 and the other a void pointer.

-kyle
Raghu,
thank u for ur reply
wll it call the function related to it by simply initilization to that
member as similar to it as others did.

Nov 13 '06 #4

P: n/a

raghu wrote:
kyle.tk wrote:
raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye
It is a pointer to a function that accepts two arguments, one of type
SDS_UINT32 and the other a void pointer.

-kyle

Raghu,
thank u for ur reply
wll it call the function related to it by simply initilization to that
member as similar to it as others did.
Initializing the value of a function pointer is a distinctly different
operation than using the function pointer to invoke a subroutine. In
the first case you are setting the value of the function pointer
variable to the address of some code subroutine. In the latter case a
properly initialized function pointer may be used to indirectly call
the subroutine that the is pointed to. They have their usage in program
code where some part of the program may need to call a different
subroutine for each pass through that code.

Now all that said ... function pointers are straightforward ... but can
be very confusing to someone just getting started using them. The
declaration syntax and the invocation syntax can get quite complex
looking when the function pointers specify many arguments and have
return values. On the other hand the function pointer is a very
powerful construct of the C language. If you learn to use them in your
C programs and then find a need to work in another language that does
not have function pointers you can become very frustrated with this
other language.

- mkaras

Nov 13 '06 #5

P: n/a
On the other hand the function pointer is a very
powerful construct of the C language. If you learn to use them in your
C programs and then find a need to work in another language that does
not have function pointers you can become very frustrated with this
other language.

- mkaras
It would be great if you can you show an example where in a
invocation of a function via pointer makes more sense than a direct
function call?

Nov 13 '06 #6

P: n/a
sa*****@yahoo.co.in wrote:
>>On the other hand the function pointer is a very
powerful construct of the C language. If you learn to use them in your
C programs and then find a need to work in another language that does
not have function pointers you can become very frustrated with this
other language.

- mkaras


It would be great if you can you show an example where in a
invocation of a function via pointer makes more sense than a direct
function call?
I think you have partly answered your own question, it is common
practice in device drivers to have function pointers to read, write or
control functions as members of a control structure.

The user initialises the function pointers to point to the appropriate
functions in their code and passes the structure to the driver.

--
Ian Collins.
Nov 13 '06 #7

P: n/a

mkaras wrote:
raghu wrote:
kyle.tk wrote:
raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye
>
It is a pointer to a function that accepts two arguments, one of type
SDS_UINT32 and the other a void pointer.
>
-kyle
Raghu,
thank u for ur reply
wll it call the function related to it by simply initilization to that
member as similar to it as others did.

Initializing the value of a function pointer is a distinctly different
operation than using the function pointer to invoke a subroutine. In
the first case you are setting the value of the function pointer
variable to the address of some code subroutine. In the latter case a
properly initialized function pointer may be used to indirectly call
the subroutine that the is pointed to. They have their usage in program
code where some part of the program may need to call a different
subroutine for each pass through that code.

Now all that said ... function pointers are straightforward ... but can
be very confusing to someone just getting started using them. The
declaration syntax and the invocation syntax can get quite complex
looking when the function pointers specify many arguments and have
return values. On the other hand the function pointer is a very
powerful construct of the C language. If you learn to use them in your
C programs and then find a need to work in another language that does
not have function pointers you can become very frustrated with this
other language.

- mkaras

Can u please give me an example for this type
Does this statement
c-func(45,(void *)chara)

Nov 13 '06 #8

P: n/a

mkaras wrote:
raghu wrote:
kyle.tk wrote:
raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
Thanks in advance
Bye
>
It is a pointer to a function that accepts two arguments, one of type
SDS_UINT32 and the other a void pointer.
>
-kyle
Raghu,
thank u for ur reply
wll it call the function related to it by simply initilization to that
member as similar to it as others did.

Initializing the value of a function pointer is a distinctly different
operation than using the function pointer to invoke a subroutine. In
the first case you are setting the value of the function pointer
variable to the address of some code subroutine. In the latter case a
properly initialized function pointer may be used to indirectly call
the subroutine that the is pointed to. They have their usage in program
code where some part of the program may need to call a different
subroutine for each pass through that code.

Now all that said ... function pointers are straightforward ... but can
be very confusing to someone just getting started using them. The
declaration syntax and the invocation syntax can get quite complex
looking when the function pointers specify many arguments and have
return values. On the other hand the function pointer is a very
powerful construct of the C language. If you learn to use them in your
C programs and then find a need to work in another language that does
not have function pointers you can become very frustrated with this
other language.

- mkaras

Can u please give me an example for this type
what Does this statement mean
c-func(45,(void *)chara)

Nov 13 '06 #9

P: n/a
what Does this statement mean
c-func(45,(void *)chara)
Well, the function pointer which is a member of the structure object
c, is being used to invoke the function it is pointing to.

Nov 14 '06 #10

P: n/a
sa*****@yahoo.co.in said:
>
>what Does this statement mean
c-func(45,(void *)chara)

Well, the function pointer which is a member of the structure object
c, is being used to invoke the function it is pointing to.
Wrong. c is not a structure object. It's a pointer (or there's a syntax
error in the above).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 14 '06 #11

P: n/a
raghu wrote:
hello,
Iam going through a document contianing C tricks .In it they
used the statement in many places i didn't understand can u please tell
me the meaning and how the compiler compiles it and runs it
The statement is :
void (* func)( SDS_UINT32 , void * );
which is a member of structure
One instructive example is the VM implementation on Linux,
here you can locate the vm_operations_struct:

struct vm_operations_struct
{
void (*open)(struct vm_arena_struct *);
void (*close)(struct vm_arena_struct *);
void (*unmap)(struct vm_arena_struct * ...);
void (*protect)(struct vm_arena_struct * ...);
void (*sync)(struct vm_arena_struct * ...);
....
};

this structure defines the possible function pointers, thus
allowing different operations to be assigned for different
virtual memory areas.

Likewise, operations for file system, communication, device
drivers can be designed in the same way, allowing for dynamic
loading of the allowed operations.

--
Tor <torust AT online DOT no>

Nov 14 '06 #12

P: n/a

sa*****@yahoo.co.in wrote:
what Does this statement mean
c-func(45,(void *)chara)

Well, the function pointer which is a member of the structure object
c, is being used to invoke the function it is pointing to.
No, c is a pointer. Besides the above will generate a syntax error.

Nov 14 '06 #13

P: n/a

sa*****@yahoo.co.in wrote:
what Does this statement mean
c-func(45,(void *)chara)

Well, the function pointer which is a member of the structure object
c, is being used to invoke the function it is pointing to.
Hello
thanks for ur valuable information i have another doubt,
then how does it will work
Suppose C()is a function with 2 arguments of structure types
can we call D(32,c) where D is another funtion and tell me how it
executes means wheather c is executed first or D or depending on the
situation D will call The C function using the pointer.
Kindly give me the reply
thanks in advance
Bye

Nov 14 '06 #14

P: n/a

>.Hello
thanks for ur valuable information i have another doubt,
then how does it will work
Suppose C()is a function with 2 arguments of structure types
can we call D(32,c) where D is another funtion and tell me how it
executes means wheather c is executed first or D or depending on the
situation D will call The C function using the pointer.
Kindly give me the reply
thanks in advance
Bye
Please post your code...

Nov 14 '06 #15

P: n/a

sa*****@yahoo.co.in wrote:
.Hello
thanks for ur valuable information i have another doubt,
then how does it will work
Suppose C()is a function with 2 arguments of structure types
can we call D(32,c) where D is another funtion and tell me how it
executes means wheather c is executed first or D or depending on the
situation D will call The C function using the pointer.
Kindly give me the reply
thanks in advance
Bye

Please post your code...
struct
C
{

void (** M)( struct Mi * );

} ;
C( INT i, void (* M)( struct Mi* ) )

{

int result = SUCCESS;
struct g * gc;

gc->M[i] = M;

return result;

}
this function can be called by
C(32, D);
where D is a function lets say it prints some message like "hello
world".
This is my actual code format .
I am waiting for ur information
Thanks in adv
--Raghu

Nov 14 '06 #16

P: n/a
raghu said:
>
sa*****@yahoo.co.in wrote:
what Does this statement mean
c-func(45,(void *)chara)

Well, the function pointer which is a member of the structure object
c, is being used to invoke the function it is pointing to.
Hello
thanks for ur valuable information
What's so valuable about it? It's wrong!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 14 '06 #17

P: n/a


On Nov 14, 7:07 pm, "raghu" <ragavaku...@gmail.comwrote:
sam_...@yahoo.co.in wrote:
>.Hello
thanks for ur valuable information i have another doubt,
then how does it will work
Suppose C()is a function with 2 arguments of structure types
can we call D(32,c) where D is another funtion and tell me how it
executes means wheather c is executed first or D or depending on the
situation D will call The C function using the pointer.
Kindly give me the reply
thanks in advance
Bye
Please post your code...struct
C

{

void (** M)( struct Mi * );

} ; C( INT i, void (* M)( struct Mi* ) )

{

int result = SUCCESS;

struct g * gc;

gc->M[i] = M;

return result;

}this function can be called by
C(32, D);
where D is a function lets say it prints some message like "hello
world".
This is my actual code format .
I am waiting for ur information
Thanks in adv
--Raghu

Does this compile? Anyways, i don't see the code invoking the
function pointed to by the pointers...

Nov 14 '06 #18

P: n/a
raghu wrote:
sa*****@yahoo.co.in wrote:
>>thanks for ur valuable information i have another doubt,
then how does it will work
Suppose C()is a function with 2 arguments of structure types
can we call D(32,c) where D is another funtion and tell me how it
executes means wheather c is executed first or D or depending on
the situation D will call The C function using the pointer.

Please post your code...

struct
C
{

void (** M)( struct Mi * );
} ;
C( INT i, void (* M)( struct Mi* ) )
{
int result = SUCCESS;
struct g * gc;

gc->M[i] = M;
return result;
}
Post compilable code. The above is nonsense.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Nov 14 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.