Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,039 of 33,346    |
|    Bart van Ingen Schenau to James K. Lowden    |
|    Re: compilers, endianness and padding    |
|    14 May 13 15:08:22    |
   
   From: bart@ingen.ddns.info.invalid   
      
   On Mon, 13 May 2013 23:11:46 -0700, James K. Lowden wrote:   
      
   > We don't need *the* one correct way. We would benefit, though, from a   
   > correct, reversible way. There is no reason it can't be done   
   > mechanically.   
   >   
   > For the reader's reference, the struct in question is   
   >   
   > struct node { int value; node* left; node* right; } n;   
   >   
   > How, you ask? I'd do something I bet very like what you would do. What   
   > I do not see is why the standard library couldn't do it for me, with a   
   > little information from the compiler.   
   >   
   > I hope someone better versed in graph theory will come to my rescue, but   
   > here's a plausible Monday night hack:   
   >   
   > byte type size value   
   > 0 node 20 -   
   > 0 int 4 x   
   > 4 node* 8 20   
   > 12 node* 8 40   
   > 20 node 20 - // n.left   
   > 20 int 4 y   
   > 24 node* 8 60   
   > 32 node* 8 80   
   > 40 node 20 -   
   > 40 int 4 z // n.right   
   > 44 node* 8 100   
   > 52 node* 8 120   
   > etc.   
   >   
   > I wrote that in ASCII of course, because we're two humans communicating.   
   > For communication between C++ programs, the above information would   
   > better be tokenized.   
      
   Trees are not that difficult to serialize. How about a slightly more   
   complex structure:   
      
   class X {   
    struct t {   
    size_t a;   
    char* b;   
    };   
      
    size_t c;   
    union {   
    char d[sizeof(t)];   
    t e;   
    } f;   
   };   
      
      
   An astute reader might recognize this as a possible layout for   
   std::string with short-string optimization. I have deliberately used non-   
   descriptive names for the members, because the compiler can't derive   
   meaning from the names either.   
   What would an auto-generated serialization format for this structure look   
   like?   
      
   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca