473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sizeof with function type

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
2 1600
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunil Menon | last post by:
Dear All, A class having no member variables and only a method sizeof(object) will return 1byte in ANSI and two bytes in Unicode. I have the answer for this of how in works in ANSI. But I don't...
2
by: Xiangliang Meng | last post by:
Hi, all. What will we get from sizeof(a class without data members and virtual functions)? For example: class abnormity { public: string name() { return "abnormity"; }
2
by: Ronald A. Andersen | last post by:
********** header **************** struct articleFile2 { char CR; int intStampDate; }; *********** source *************** struct articleFile2 *ptrArticle2 = NULL;
9
by: Vijay Kumar R Zanvar | last post by:
Hi, Why the following program gives two different answers? - #include <stdio.h> int main ( void ) {
42
by: Christopher C. Stacy | last post by:
Some people say sizeof(type) and other say sizeof(variable). Why?
90
by: pnreddy1976 | last post by:
Hi, How can we write a function, which functionality is similar to sizeof function any one send me source code Reddy
28
by: Howard Bryce | last post by:
I have come across code containing things like sizeof int How come that one can invoke sizeof without any parentheses surrounding its argument? Is this admissible within the standard? Can it...
38
by: James Brown | last post by:
All, I have a quick question regarding the size of pointer-types: I believe that the sizeof(char *) may not necessarily be the same as sizeof(int *) ? But how about multiple levels of pointers...
17
by: venkat | last post by:
Hi, I have written a program void main() { printf("%d %d\n", sizeof main, sizeof(main())); } in this program the output is 1 and 4,
8
by: c.lang.myself | last post by:
whenever we pass an array to function, we have to also pass its size.e.g if i am making a soritng function then void sort(int b,int size); Now I thought about using sizeof operator(macro?)...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.