C++: Getting Type of a Construct

From: Gene Wirchenko (gwirchenkoEXCEPT_at_CAPITALSwencomine.com)
Date: 10/31/03


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



Relevant Pages

  • Re: Unstaffed stations and tickets: the Virgin approach (long, sorry)
    ... > Can I refer you to the postingthat, inter alia, said things like? ... > That's certainly very consistent with the Daily Mail/Express worldview. ... misinterpret plain English postings to suit your own prejudice of the ...
    (uk.railway)
  • Re: Latest version of Kogos Joseki Dictionary has display problems with CGoban 2.6.12
    ... that some labeling markers are absent in this version of KJD. ... To be consistent, ...
    (rec.games.go)
  • Re: function pointers
    ... If you consistently use "pointer" to refer to pointer objects, ... "address" to refer to values, ... consistent with the C standard -- but the language used in the C ...
    (comp.lang.c)
  • Re: Class Variable Access and Assignment
    ... > I would expect a result consistent with the fact that both times b.a ... > would refer to the same object. ... The problem with the world is stupidity. ... safety labels off of everything and let the problem solve itself? ...
    (comp.lang.python)
  • Re: External Reference
    ... Insert/Name/Define listbox to see if a defined name refers to an ... external file. ... > Is there a way to find the cells that refer to another file in Excel 2000? ...
    (microsoft.public.excel.misc)