[Effective-cpp] Item 34: Understand How to Combine C++ and C in the Same Program.

Adrian Fagg AdrianF at evaluategroup.com
Fri Jun 6 06:14:44 EDT 2003


> -----Original Message-----
> From: Klitos Kyriacou [mailto:Klitos.Kyriacou at reuters.com]

> > Adding virtual functions, 
> > however, causes structs to use a different memory layout, and 
> > transfer is 
> > no longer possible.
> 
> Is this necessarily true? If you slice a derived class that 
> has virtual
> functions into a POD, C struct (and pass it to a C function) won't the
> resulting struct have the same memory layout as the original?

There are two ways to add member functions - derivation and conditional
compilation.
The latter would be vulnerable to change if virtual functions were included,
the former would not.

When you say slice, presumably you're not talking about copying, just
casting a pointer in this case? Either way, I would have thought that you
must be right - if the same struct declaration leads to the same thing in C
and C++ with compatible compiler settings, then surely the cast must work
without surprises?

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/ 


DISCLAIMER: The contents of this e-mail are confidential and are intended
for the individual or entity named in the e-mail address. If you are not the
intended recipient (or their designated representative), you should notify
the sender immediately and delete the e-mail and any attachments. All
information contained in this e-mail is private and confidential. 

All reasonable precautions have been taken to ensure no viruses are present
in this e-mail. But as we cannot accept responsibility for loss or damage
arising from the use of this e-mail or attachments we recommend that you
subject these to your own virus checking procedures prior to use. 




--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---



More information about the Effective-cpp mailing list