C++: Getting Type of a Construct
From: Gene Wirchenko (gwirchenkoEXCEPT_at_CAPITALSwencomine.com)
Date: 10/31/03
- Next message: Andrey Tarasevich: "Re: [OT] Glasses"
- Previous message: David White: "Re: Pointers and Arrays in C"
- Next in thread: Martijn Lievaart: "Re: C++: Getting Type of a Construct"
- Reply: Martijn Lievaart: "Re: C++: Getting Type of a Construct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 01:21:15 GMT
Despite the appearance, this is an implementation-independent
question. I am writing an application that uses Winsock. I wish to
be as consistent as possible in type use. I do not have the luxury of
being able to change winsock.h. The relevant portion of it, defining
IP addresses, is:
struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
#define s_addr S_un.S_addr
/* can be used for most tcp & ip code
*/
[...]
};
I wish my code to agree with this as much as possible, and I want
that agreement to be *automatic*. If the .h changes in the next
release, I want my program to follow along. I do not have the option
of changing this file. Is there any way to pick up the type of an
object defined in an external file?
I would like to able to say:
typedef <typeof S_addr> IPAddr_Type;
and use IPAddr_Type throughout my program. I am able to use
IPAddr_Type, but only if I do
typedef in_addr IPAddr_Type;
Because of doing that, whenever I refer to S_addr, I have to do it the
long way
typedef in_addr IPAddr_Type;
IPAddr_Type MemberVar;
and referring to it with
MemberVar.s_addr
I am glad to have s_addr; otherwise references would be
MemberVar.S_un.S_addr
I would much rather have
typedef <typeof S_addr> IPAddr_type;
IPAddr_Type MemberVar;
and refer to it with
MemberVar
What would I do if it were not a structure as in
// some kind of thing
long SomeVar;
How would I pick up that type so I could declare
// Save the SomeVar!
<somethinghere> SaveSomeVar=SomeVar;
Lastly, if there is a different answer for C code, what is it,
please?
Sincerely,
Gene Wirchenko
- Next message: Andrey Tarasevich: "Re: [OT] Glasses"
- Previous message: David White: "Re: Pointers and Arrays in C"
- Next in thread: Martijn Lievaart: "Re: C++: Getting Type of a Construct"
- Reply: Martijn Lievaart: "Re: C++: Getting Type of a Construct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|