473,769 Members | 5,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a typedef question

Hello, this is a follow-up question I had about typedef usage in Gianni
Mariani's thread:
news://213.88.137.53:1 19/46************* **********@per-qv1-newsreader-01.iinet.net.au

int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof(foo(ii() , pi()));
}
I understand the function foo never actually gets called, but what
causes the compiler to ignore this usage (without any actual storage
unit or variable declaration)? Normally one cannot call a function like
this. Also I didn't find any reference that sizeof can be used to take
the size of a function return type during compile time. I know what this
code is doing and it makes sense to me. But it seems like I can't find
any reference that says this is correct and proper use of C++ syntax.

This is the first time this kind of sizeof and typedef usage get my
attention, where I can read/learn about this typedef trick?

Thanks,

Fei
Apr 10 '07 #1
4 1717
Fei Liu wrote:
[..]
int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof(foo(ii() , pi()));
}
I understand the function foo never actually gets called, but what
causes the compiler to ignore this usage (without any actual storage
unit or variable declaration)?
5.3.3/1 Sizeof
"... The operand is either an expression *which is not evaluated* ..."
(emphasis mine).
Normally one cannot call a function
like this.
Not sure what you meant by "normally". And how is it "like this"?
Temporaries of type 'ii' and 'pi' are constructed and passed to the
function. Just remove 'sizeof' and see what happens.
Also I didn't find any reference that sizeof can be used
to take the size of a function return type during compile time.
Again, 5.3.3/1. What of "an expression" do you not get?
I
know what this code is doing and it makes sense to me. But it seems
like I can't find any reference that says this is correct and proper
use of C++ syntax.
This is the first time this kind of sizeof and typedef usage get my
attention, where I can read/learn about this typedef trick?
WHAT typedef trick? You mean you never seen something like "blah()"
for 'blah' that is a type?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 10 '07 #2
Victor Bazarov wrote:
Fei Liu wrote:
>[..]
int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof(foo(ii() , pi()));
}
I understand the function foo never actually gets called, but what
causes the compiler to ignore this usage (without any actual storage
unit or variable declaration)?

5.3.3/1 Sizeof
"... The operand is either an expression *which is not evaluated* ..."
(emphasis mine).
>Normally one cannot call a function
like this.

Not sure what you meant by "normally". And how is it "like this"?
Temporaries of type 'ii' and 'pi' are constructed and passed to the
function. Just remove 'sizeof' and see what happens.
>Also I didn't find any reference that sizeof can be used
to take the size of a function return type during compile time.

Again, 5.3.3/1. What of "an expression" do you not get?
>I
know what this code is doing and it makes sense to me. But it seems
like I can't find any reference that says this is correct and proper
use of C++ syntax.
This is the first time this kind of sizeof and typedef usage get my
attention, where I can read/learn about this typedef trick?

WHAT typedef trick? You mean you never seen something like "blah()"
for 'blah' that is a type?

V
Thanks for the pointer to 5.3.3/1 in the standard. But seriously, did
you forget to take your medicine?
Apr 10 '07 #3
Fei Liu wrote:
Victor Bazarov wrote:
>Fei Liu wrote:
>>[..]
int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof(foo(ii() , pi()));
}
I understand the function foo never actually gets called, but what
causes the compiler to ignore this usage (without any actual storage
unit or variable declaration)?

5.3.3/1 Sizeof
"... The operand is either an expression *which is not evaluated*
..." (emphasis mine).
>>Normally one cannot call a function
like this.

Not sure what you meant by "normally". And how is it "like this"?
Temporaries of type 'ii' and 'pi' are constructed and passed to the
function. Just remove 'sizeof' and see what happens.
>>Also I didn't find any reference that sizeof can be used
to take the size of a function return type during compile time.

Again, 5.3.3/1. What of "an expression" do you not get?
>>I
know what this code is doing and it makes sense to me. But it seems
like I can't find any reference that says this is correct and proper
use of C++ syntax.
This is the first time this kind of sizeof and typedef usage get my
attention, where I can read/learn about this typedef trick?

WHAT typedef trick? You mean you never seen something like "blah()"
for 'blah' that is a type?

V

Thanks for the pointer to 5.3.3/1 in the standard. But seriously, did
you forget to take your medicine?
What makes you think there is some medicine I am usually taking?
Are you a doctor?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 10 '07 #4
On Apr 11, 5:50 am, Fei Liu <fei...@aepnetw orks.comwrote:
Victor Bazarov wrote:
Fei Liu wrote:
[..]
int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof(foo(ii() , pi()));
}
This is the first time this kind of sizeof and typedef usage get my
attention, where I can read/learn about this typedef trick?
WHAT typedef trick? You mean you never seen something like "blah()"
for 'blah' that is a type?

Thanks for the pointer to 5.3.3/1 in the standard. But seriously, did
you forget to take your medicine?
FWIW, I too have no idea what you meant by "typedef trick". The two
typedefs in the original code are pretty basic, it's hard to imagine
a simpler typedef. I also have no idea what you meant by:
I understand the function foo never actually gets called, but what
causes the compiler to ignore this usage (without any actual storage
unit or variable declaration)?
unless perhaps, as Victor hypothesized, you aren't familiar
with the syntax T() for creating a temporary of type T, or
if you aren't aware that the sizeof operator can be applied
to any expression.

Can you explain?

#include <stdio.h>

int foo(int A, int * pA){ return 0; }
int main(){
typedef int * pi;
typedef int ii;
int a = sizeof foo(ii(), pi());
int b = foo(ii(), pi());
printf("a = %d, b = %d\n", a, b); /* probably 4, 0 */
return 0;
}

Apr 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2960
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the following error messages: warning: implicit typename is deprecated, please see the documentation for details Can someone kindly suggest how to get rid of these warnings? The source code follows.
7
2148
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type y = x; but I can't understand the last one which is Array<int>::element_type y = x; We have a typedef T element_type; in the template Array class see below
30
4273
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
6
7347
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if (condition) typedef char T; #else typedef short T;
12
8246
by: Thomas Carter | last post by:
Imagine that there is some include file f.h that contains the following line: typedef unsigned int ui32 ; My question is: If I have a C source file F.c that includes f.h, is it possible for the preprocessor to detect that ui32 already exists, when preprocessing F.c? The idea is that F.c will typedef ui32 as above if and only if such typedef is not already in some include file used by F.c.
7
15297
by: Michael B Allen | last post by:
I have a forward reference like: struct foo; int some_fn(struct foo *param); Because the parameter is a pointer the compiler is satisfied. But now I wan to change 'struct foo' to a typedef'd type like 'foo_t'. The following all fail to compile:
12
4653
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int (*(*(*ptr2d_fptr)()))();
16
2784
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the threads, there is sound advice ( to me at any rate) not to hide pointers behind typedefs. So, may I ask the group when the use of typedefs really makes sense? Sorry if this is somewhat general, but there are no exercises ( not that I am asking for...
7
18450
by: MJ_India | last post by:
Style 1: struct my_struct { ... }; typedef my_struct my_struct_t; Style 2: typedef struct my_struct {
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.