Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Please expplain this declaration

Reply
Thread Tools

Please expplain this declaration

 
 
fred.zakity@gmail.com
Guest
Posts: n/a
 
      05-10-2007
Can someone please explain this function pointer declaration:

float (* getptr (char opcode) ) (int, int);

I'm confused by the syntax - I have not seen a function pointer with
the extra parameter "char opcode" in the parentheses.

Thanks,
fred.

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      05-10-2007
In article < om>,
<> wrote:

>Can someone please explain this function pointer declaration:
>
>float (* getptr (char opcode) ) (int, int);


It declares getptr as a function taking a char argument called opcode
and returning a pointer to a function taking two integers and
returning a float.

>I'm confused by the syntax - I have not seen a function pointer with
>the extra parameter "char opcode" in the parentheses.


That's not an "extra parameter" - that's the ordinary part of the
declaration! The

float (* ... ) (int, int)

wrapped around it is describing the return type.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      05-10-2007
writes:

> Can someone please explain this function pointer declaration:
>
> float (* getptr (char opcode) ) (int, int);
>
> I'm confused by the syntax - I have not seen a function pointer with
> the extra parameter "char opcode" in the parentheses.


This is not a declaration of a function pointer. It is a
declaration of a function named "getptr" taking a single
parameter of type char and returning a pointer to a function
taking two int parameters and returning a float.
--
Comp-sci PhD expected before end of 2007
Seeking industrial or academic position *outside California* in 2008
 
Reply With Quote
 
fred.zakity@gmail.com
Guest
Posts: n/a
 
      05-10-2007
On May 10, 9:33 am, Ben Pfaff <b...@cs.stanford.edu> wrote:
> fred.zak...@gmail.com writes:
> > Can someone please explain this function pointer declaration:

>
> > float (* getptr (char opcode) ) (int, int);

>
> > I'm confused by the syntax - I have not seen a function pointer with
> > the extra parameter "char opcode" in the parentheses.

>
> This is not a declaration of a function pointer. It is a
> declaration of a function named "getptr" taking a single
> parameter of type char and returning a pointer to a function
> taking two int parameters and returning a float.
> --
> Comp-sci PhD expected before end of 2007
> Seeking industrial or academic position *outside California* in 2008



Thanks very much for the answers guys!
fred.

 
Reply With Quote
 
Clever Monkey
Guest
Posts: n/a
 
      05-10-2007
wrote:
> Can someone please explain this function pointer declaration:
>
> float (* getptr (char opcode) ) (int, int);
>
> I'm confused by the syntax - I have not seen a function pointer with
> the extra parameter "char opcode" in the parentheses.
>

Find a copy of "cdecl" and run it against this signature. Most versions
of the utility will describe, in English, what is going on.

I get "declare getptr as function that expects (opcode as char)
returning pointer to function that expects (int, int) returning float;"
--
clvrmnky

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
 
Reply With Quote
 
fred.zakity@gmail.com
Guest
Posts: n/a
 
      05-10-2007
On May 10, 10:15 am, Clever Monkey <spamt...@clevermonkey.org.INVALID>
wrote:
> fred.zak...@gmail.com wrote:
> > Can someone please explain this function pointer declaration:

>
> > float (* getptr (char opcode) ) (int, int);

>
> > I'm confused by the syntax - I have not seen a function pointer with
> > the extra parameter "char opcode" in the parentheses.

>
> Find a copy of "cdecl" and run it against this signature. Most versions
> of the utility will describe, in English, what is going on.
>
> I get "declare getptr as function that expects (opcode as char)
> returning pointer to function that expects (int, int) returning float;"
> --
> clvrmnky
>
> Direct replies will be blacklisted. Replace "spamtrap" with my name to
> contact me directly.


I tried Cdecl, but all I get is "parse error"!
fred

 
Reply With Quote
 
Clever Monkey
Guest
Posts: n/a
 
      05-10-2007
wrote:
> On May 10, 10:15 am, Clever Monkey <spamt...@clevermonkey.org.INVALID>
> wrote:
>> fred.zak...@gmail.com wrote:
>>> Can someone please explain this function pointer declaration:
>>> float (* getptr (char opcode) ) (int, int);
>>> I'm confused by the syntax - I have not seen a function pointer with
>>> the extra parameter "char opcode" in the parentheses.

>> Find a copy of "cdecl" and run it against this signature. Most versions
>> of the utility will describe, in English, what is going on.
>>
>> I get "declare getptr as function that expects (opcode as char)
>> returning pointer to function that expects (int, int) returning float;"
>> --
>> clvrmnky
>>
>> Direct replies will be blacklisted. Replace "spamtrap" with my name to
>> contact me directly.

>
> I tried Cdecl, but all I get is "parse error"!
> fred
>

Check the documentation. My cdecl needs to read the entries from a
file, and they must be "correct" and have a trailing ";"
--
clvrmnky <private.php?do=newpm&u=>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      05-10-2007
Clever Monkey wrote:

> wrote:
> > Can someone please explain this function pointer declaration:
> >
> > float (* getptr (char opcode) ) (int, int);
> >
> > I'm confused by the syntax - I have not seen a function pointer with
> > the extra parameter "char opcode" in the parentheses.
> >

> Find a copy of "cdecl" and run it against this signature. Most
> versions of the utility will describe, in English, what is going on.
>
> I get "declare getptr as function that expects (opcode as char)
> returning pointer to function that expects (int, int) returning
> float;"


Has anybody seen an online cdecl? One where you could paste a
declaration into a web form and get back the result?

It seems like the sort of thing somebody might do, like all those
online calculators for various things, but I didn't have any luck
searching for one.



Brian
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-11-2007
CBFalconer <> writes:
> Clever Monkey wrote:
>> wrote:
>>
>>> Can someone please explain this function pointer declaration:
>>>
>>> float (* getptr (char opcode) ) (int, int);
>>>
>>> I'm confused by the syntax - I have not seen a function pointer
>>> with the extra parameter "char opcode" in the parentheses.

>>
>> Find a copy of "cdecl" and run it against this signature. Most
>> versions of the utility will describe, in English, what is going
>> on.
>>
>> I get "declare getptr as function that expects (opcode as char)
>> returning pointer to function that expects (int, int) returning
>> float;"

>
> I get 'parse error'.


So do I (actually "syntax error", not "parse error"), but the error
message goes away if I delete the parameter name "opcode":

% cdecl -V
Version:
@(#)cdecl.c 2.5 1/15/96
@(#)cdgram.y 2.2 3/30/88
@(#)cdlex.l 2.2 3/30/88
% cdecl
Type `help' or `?' for help
cdecl> explain float (* getptr (char opcode) ) (int, int)
syntax error
cdecl> explain float (* getptr (char) ) (int, int)
declare getptr as function (char) returning pointer to function (int, int) returning float
cdecl>

Perhaps different versions of cdecl handle this differently.

--
Keith Thompson (The_Other_Keith) kst- <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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Wolfram Ladurner
Guest
Posts: n/a
 
      05-11-2007
Am Thu, 10 May 2007 09:31:19 -0700 schrieb fred.zakity:

> On May 10, 10:15 am, Clever Monkey <spamt...@clevermonkey.org.INVALID>
> wrote:
>> fred.zak...@gmail.com wrote:
>> > Can someone please explain this function pointer declaration:

>>
>> > float (* getptr (char opcode) ) (int, int);

<snip>
>> Find a copy of "cdecl" and run it against this signature.

<snip>
> I tried Cdecl, but all I get is "parse error"!
> fred


Leave out the "opcode":

cdecl> explain float (*getptr(char))(int, int)

and it will work.

hth,
Wolfram
 
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
Can a static function declaration conflict with a non-static declaration? nospam_timur@tabi.org C Programming 4 12-12-2006 10:26 PM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
"virtual outside class declaration" and "declaration does not declare anything" kelvSYC C++ 6 05-17-2005 08:58 AM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM
Intel C++ 8.0 : declaration hides declaration Alex Vinokur C++ 4 04-05-2004 09:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57