473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

what the statement in a structure mean

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
18 2496

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

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

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

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
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
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

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

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
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
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
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

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

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

>.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

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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
37
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
6
by: wintaki | last post by:
Given int x; What does x evaluate to? If x is 0, it equals 0x31, the ascii value of '1'. So for some reason, x evaluates to *(y+x) where x is a non pointer/array type.
28
by: Vishal Naidu | last post by:
i m new to the C world... i ve been told by my instructors not to use goto stmt.. but no one could give me a satisfactory answer as to why it is so.. plz help me out of this dilemma, coz i use...
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
7
by: Umesh | last post by:
what this statement &(*IR)->func means. where IR is the pointer to structure & func is pointer to fuction. func is the member of structure.
11
by: dhan | last post by:
please give answer
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.