C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

function as a parameter

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
maths_fan
Guest





PostPosted: Fri Feb 27, 2004 2:49 pm    Post subject: function as a parameter Reply with quote



I know that the correct is when I write:

void g(int);
void f(void*);
.............
f(g);

But my compiler (Visual C++ 6 and .NET) don't mind when I use it like this:

f(void g(int a));

Is it correct by standard of C++ to write like this?

Thanks in advance.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ben Hutchings
Guest





PostPosted: Sat Feb 28, 2004 3:43 am    Post subject: Re: function as a parameter Reply with quote



maths_fan wrote:
Quote:
I know that the correct is when I write:

void g(int);
void f(void*);
............
f(g);

No, that's not correct. There is no standard conversion from
pointer-to-function to void *. There are good reasons for this,
including the fact that code and data may be stored in separate
address spaces, particularly in micro-controllers.

Quote:
But my compiler (Visual C++ 6 and .NET) don't mind when I use it like this:

f(void g(int a));

Is it correct by standard of C++ to write like this?

No, it's not correct. What you've written there is a declaration
(though of an archaic and non-standard form) rather than an
expression. The parameter names g and a are ignored, the function
type given as a parameter type is "adjusted" to a pointer-to-function
type, and the return type is assumed to be int. So it is equivalent
to:

int f(void (*)(int));

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.