Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: decoding a declaration

Reply
Thread Tools

Re: decoding a declaration

 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-16-2010
"t" <(E-Mail Removed)> writes:

> I am trying to decode a declaration "void *(*p[]) (void *a, int n)"
>
> Does it mean an array of pointers to a function taking
> two parameters(one a void pointer, another an integer)
> and returning a void pointer?


Yup. That's it.

> Or am I missing something? Which would be a good book
> to understand how to decode such declarations?


I don't know of a book, but you seem to have the hang of it. You read
inside out from the name (respecting brackets), moving left in
preference to moving right.

There's a utility -- cdecl that can turn them into text. I don't know
if it works for C++ (I just noticed the cross-post!).

<snip>
--
Ben.
 
Reply With Quote
 
 
 
 
David Thompson
Guest
Posts: n/a
 
      03-04-2010
On Tue, 16 Feb 2010 21:28:25 +0000, Ben Bacarisse
<(E-Mail Removed)> wrote:

> "t" <(E-Mail Removed)> writes:
>
> > I am trying to decode a declaration "void *(*p[]) (void *a, int n)"
> >
> > Does it mean an array of pointers to a function taking
> > two parameters(one a void pointer, another an integer)
> > and returning a void pointer?

>
> Yup. That's it.
>
> > Or am I missing something? Which would be a good book
> > to understand how to decode such declarations?

>
> I don't know of a book, but you seem to have the hang of it. You read
> inside out from the name (respecting brackets), moving left in
> preference to moving right.
>

Other way; array and function to the right must be taken before
pointer (or C++ reference) to the left.
Overridden by en_GB brackets = en_US parentheses, to be clear.

 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      03-04-2010
David Thompson <(E-Mail Removed)> writes:
>Other way; array and function to the right must be taken before
>pointer (or C++ reference) to the left.


Yes, and these are just the same precedence rules as for
expressions. Therefore, earlier in this thread, I suggested
mentally translating it to an assertion about the type of an
expression. Someone who already knows the precedence rules
for expressions, does not have to learn any additional
precendence rule for declarations.

When people learn latin or french, they learn literally
several ten thousands words and declension rules, so it
might not be asked too much that a C programmer learns
the priorities of one or two dozens of operators.

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      03-04-2010
David Thompson <(E-Mail Removed)> writes:

> On Tue, 16 Feb 2010 21:28:25 +0000, Ben Bacarisse
> <(E-Mail Removed)> wrote:
>
>> "t" <(E-Mail Removed)> writes:
>>
>> > I am trying to decode a declaration "void *(*p[]) (void *a, int n)"
>> >
>> > Does it mean an array of pointers to a function taking
>> > two parameters(one a void pointer, another an integer)
>> > and returning a void pointer?

>>
>> Yup. That's it.
>>
>> > Or am I missing something? Which would be a good book
>> > to understand how to decode such declarations?

>>
>> I don't know of a book, but you seem to have the hang of it. You read
>> inside out from the name (respecting brackets), moving left in
>> preference to moving right.
>>

> Other way;


Would you believe I get left and right confused? Extraordinary but
true. I usually pause and check multiple times when I write either
but even then this can happen. I don't confuse the /directions/ its
is their, to me, arbitrary names that cause the trouble!

--
Ben.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      03-04-2010
Ben Bacarisse <(E-Mail Removed)> writes:
>is their, to me, arbitrary names that cause the trouble!


The names are not arbitrary.

Look at the word »Left«.

The »L« of »Left« is a horizontal rule (bar), like »_«.

But which side of the rule is left?

There's a vertical mark on the /left/ side of the rule: »L«.

And, where in the word »Left« is the »L« located?

On the /left/ side of the word.

And what happens, when you write »left« and »right« in
alphabetical order?

left right

When you then read this, the word »left« is left and
the word »right« is right.

So it all comes out right. (Even in this sentence, the
word »right« is in the rightmost position.)

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      03-10-2010
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) wrote:

> Ben Bacarisse <(E-Mail Removed)> writes:
> >is their, to me, arbitrary names that cause the trouble!

>
> The names are not arbitrary.
>
> Look at the word »Left«.


> There's a vertical mark on the /left/ side of the rule: »L«.


> And what happens, when you write »left« and »right« in
> alphabetical order?
>
> left right
>
> When you then read this, the word »left« is left and
> the word »right« is right.
>
> So it all comes out right. (Even in this sentence, the
> word »right« is in the rightmost position.)


From this, I conclude that Frenchmen and Italians are looking-glass
creatures.

Richard
 
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: decoding a declaration Ben Bacarisse C Programming 6 03-10-2010 02:14 PM
Re: decoding a declaration Stefan Ram C++ 5 02-17-2010 07:23 PM
Re: decoding a declaration Stefan Ram C Programming 5 02-17-2010 07:23 PM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
Intel C++ 8.0 : declaration hides declaration Alex Vinokur C++ 4 04-05-2004 09:49 PM



Advertisments