Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to define a function pointer variable witout typdef?

Reply
Thread Tools

how to define a function pointer variable witout typdef?

 
 
baumann@pan
Guest
Posts: n/a
 
      05-27-2005
hi all,

typedef int (*pfunc)(int , int);
pfunc a_func;

i know it's ok,

but how can define a_func without typedef statement?

thanks .

baumann@pan

 
Reply With Quote
 
 
 
 
Robert Gamble
Guest
Posts: n/a
 
      05-27-2005
baumann@pan wrote:
> hi all,
>
> typedef int (*pfunc)(int , int);
> pfunc a_func;
>
> i know it's ok,
>
> but how can define a_func without typedef statement?


int (*a_func)(int, int);

Rob Gamble

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-27-2005
baumann@pan wrote:
> hi all,
>
> typedef int (*pfunc)(int , int);
> pfunc a_func;
>
> i know it's ok,
>
> but how can define a_func without typedef statement?
>


int (*a_func)(int, int);

cdecl <<EOD
explain int (*a_func)(int, int)
quit
EOD
declare a_func as pointer to function (int, int) returning int
 
Reply With Quote
 
sathyashrayan
Guest
Posts: n/a
 
      05-27-2005

"baumann@pan" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) oups.com...
> hi all,
>
> typedef int (*pfunc)(int , int);
> pfunc a_func;
>
> i know it's ok,
>
> but how can define a_func without typedef statement?
>
> thanks .
>


int (*a_func)(int, int);
But this is a declaration not a definition.


--
"combination is the heart of chess"

A.Alekhine

Mail to:
sathyashrayan AT gmail DOT com



 
Reply With Quote
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      05-27-2005
sathyashrayan <(E-Mail Removed)> wrote:

> "baumann@pan" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) oups.com...
>> typedef int (*pfunc)(int , int);
>> pfunc a_func;
>>
>> i know it's ok,
>>
>> but how can define a_func without typedef statement?


> int (*a_func)(int, int);
> But this is a declaration not a definition.


No, this creates a variable, named 'a_func', that can hold a pointer
to a function taking two int arguments and returning an int. No
'extern' to see seen in front of it, so it's a definition, not a
declaration.
Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      05-27-2005
(E-Mail Removed)-berlin.de wrote:
> sathyashrayan <(E-Mail Removed)> wrote:
>> "baumann@pan" <(E-Mail Removed)> wrote in message

>
>>> typedef int (*pfunc)(int , int);
>>> pfunc a_func;
>>>
>>> i know it's ok,
>>>
>>> but how can define a_func without typedef statement?

>
>> int (*a_func)(int, int);
>> But this is a declaration not a definition.

>
> No, this creates a variable, named 'a_func', that can hold a
> pointer to a function taking two int arguments and returning an
> int. No 'extern' to see seen in front of it, so it's a definition,
> not a declaration.


It's a definition of a pointer variable, which in turn is useless
until filled with a pointer to a compatible function. Such a
function can be defined with:

int this_func(int a, int b)
{
/* the actual definition goes here */
}

and then the statement:

a_func = this_func;

can initialize a_func, and make it usable. Because there is no '('
immediately following a_func or this_func these are pointer values,
not function calls.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      05-27-2005
(E-Mail Removed)-berlin.de wrote:
>
> sathyashrayan <(E-Mail Removed)> wrote:
>
> > "baumann@pan" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> >> typedef int (*pfunc)(int , int);
> >> pfunc a_func;
> >>
> >> i know it's ok,
> >>
> >> but how can define a_func without typedef statement?

>
> > int (*a_func)(int, int);
> > But this is a declaration not a definition.

>
> No, this creates a variable, named 'a_func', that can hold a pointer
> to a function taking two int arguments and returning an int. No
> 'extern' to see seen in front of it, so it's a definition, not a
> declaration.


It's a definition and a declaration.

--
pete
 
Reply With Quote
 
E. Robert Tisdale
Guest
Posts: n/a
 
      05-28-2005
baumann@pan wrote:

> typedef int (*pfunc)(int , int);
> pfunc a_func;
>
> I know it's ok,
> but how can I define a_func without typedef statement?


> cat main.c

#include <stdio.h>

int this_func(const int a, const int b) {
return fprintf(stdout, "a = %d\tb = %d\n", a, b);
}

int (*a_func)(int, int) = this_func;

int main(int argc, char* argv[]) {
a_func(13, 42);
return 0;
}

> gcc -Wall -std=c99 -pedantic -o main main.c
> ./main

a = 13 b = 42
 
Reply With Quote
 
sathyashrayan
Guest
Posts: n/a
 
      05-28-2005

<(E-Mail Removed)-berlin.de> wrote in message news:(E-Mail Removed)...
> sathyashrayan <(E-Mail Removed)> wrote:
>
> > "baumann@pan" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) oups.com...
> >> typedef int (*pfunc)(int , int);
> >> pfunc a_func;
> >>
> >> i know it's ok,
> >>
> >> but how can define a_func without typedef statement?

>
> > int (*a_func)(int, int);
> > But this is a declaration not a definition.

>
> No, this creates a variable, named 'a_func', that can hold a pointer
> to a function taking two int arguments and returning an int.


Is it the declaration 'a_func' satisfies the criteria of definition
when 'a_func' pointes with the properly defined function (as you said)? Or I am missing some simple thing?


>No 'extern' to see seen in front of it, so it's a definition, not a
> declaration.


I dont understand.


--
"combination is the heart of chess"

A.Alekhine

Mail to:
sathyashrayan AT gmail DOT com



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-28-2005
"sathyashrayan" <(E-Mail Removed)> writes:
> <(E-Mail Removed)-berlin.de> wrote in message
> news:(E-Mail Removed)...
>> sathyashrayan <(E-Mail Removed)> wrote:
>>
>> > "baumann@pan" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed) oups.com...
>> >> typedef int (*pfunc)(int , int);
>> >> pfunc a_func;
>> >>
>> >> i know it's ok,
>> >>
>> >> but how can define a_func without typedef statement?

>>
>> > int (*a_func)(int, int);
>> > But this is a declaration not a definition.

>>
>> No, this creates a variable, named 'a_func', that can hold a pointer
>> to a function taking two int arguments and returning an int.

>
> Is it the declaration 'a_func' satisfies the criteria of definition
> when 'a_func' pointes with the properly defined function (as you
> said)? Or I am missing some simple thing?


It's an object definition (it defines the pointer-to-function object
"a_func"). It's just not a function definition.

Roughly speaking, a definition is a declaration that creates the
entity being declared, whereas a declaration that isn't a definition
merely declares that the entity exists, but doesn't actually create
it. (All definitions are declarations.) For example:

int x; /* a definition; it creates x */
extern int y; /* not a definition; y is defined elsewhere */
void foo(void) { printf("Hello\n"); }
/* a definition of the function "foo" */
void bar(void); /* not a definition; bar is defined elsewhere */

Typedefs are a bit odd in that a typedef doesn't actually create a new
type, merely an alias for an existing type. But a typedef is a
definition because the thing it creates is the alias, not the type.

And now we wait for the experts to point out my errors.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
About typedef -- define the function pointer or define function model? robin liu C Programming 3 04-21-2006 03:26 PM
Windows X64 crashes witout completing boot =?Utf-8?B?RW5yaXF1ZQ==?= Windows 64bit 3 06-19-2005 04:16 PM
How to create an initialise pointer to pointer to function variable; iceColdFire C++ 9 05-23-2005 07:05 AM
can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined? baumann.Pan@gmail.com C Programming 5 03-12-2005 12:29 AM



Advertisments