By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,905 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,905 IT Pros & Developers. It's quick & easy.

sizeof with function type

P: n/a
class A{};

void func() {
sizeof ( A (A()) );
sizeof ( ( A (A()) ) );
sizeof ( A ((A())) );
}

The first operand is a type-id of a function. It doesn't compile with
Comeau which is fine.

The other two are supposed to be making the operands get parsed as
expressions. The third is the typical way using extra parentheses
around the first parameter. The second compiles and the third doesn't
with Comeau.

I expected the opposite. I think the third might be a bug. I'm not
sure about the second.
Fraser.
Oct 8 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Oct 8, 6:17*pm, "Fraser Ross" <z...@zzzzzz.comwrote:
class A{};
*void func() {
sizeof *( A (A()) );
sizeof *( ( A (A()) ) );
sizeof *( A ((A())) );
* }
The first operand is a type-id of a function. *It doesn't
compile with Comeau which is fine.
The other two are supposed to be making the operands get
parsed as expressions. *The third is the typical way using
extra parentheses around the first parameter. *The second
compiles and the third doesn't with Comeau.
I expected the opposite. *I think the third might be a bug.
I'm not sure about the second.
Such declarations are tricky. According to the standard (§8.1),
"It is possible to identify uniquely the location in the
abstract-declarator where the identifier would appear if the
construction were a declarator in a declaration. The named type
is then the same as the type of the hypothetical identifier."
So if we consider your type-id's:

A (A()) -A f(A ()) -A f( A (*)() )
(A (A())) -??? I can't make this one into a declaration.
Apparently, Comeau agrees with me. If
you think it is a type-id, where do you
put the identifier?
A ((A())) -A (f(A())) -A (f (A (*)()))

The last is basically the same as the first, with an extra set
of parentheses.

Note that if you are actually writing a declaration, you provide
the symbol, rather than the compiler putting it anywhere that
will result in the desired parse. The extra parentheses that
you cite for the third, for example, work in a declaration
because there is an identifier, and it is not in the same place
as it comes out above:

A f( (A()) ) ;

If the f is inside the outer parentheses, however, this is a
legal declaration of a function.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 8 '08 #2

P: n/a
I see what is happening with the third now, thanks.

The code was reduced from P25 of Modern C++ Design. There was something
like my first operand and later it was changed to something like my
third operand. My second operand is something that works.

Fraser.
Oct 9 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.