<p>Is there a side effect in doing this:</p>

<p>C code:</p>

<pre><code>struct foo {
      int k;
};

int ret_foo(const struct foo* f){ 
    return f.k; 
}
</code></pre>

<p>C++ code:</p>

<pre><code>class bar : public foo {

   int my_bar() { 
       return ret_foo( (foo)this ); 
   }

};
</code></pre>

<p>There's an <code>extern "C"</code> around the C++ code and each code is inside its own compilation unit.</p>

<p>Is this portable across compilers?</p>

Wow, that's evil.
Is this portable across compilers?
Most definitely not. Consider the following:
```
```
foo* x = new bar();
delete x;
```
```
In order for this to work, foo's destructor must be virtual which it clearly isn't. As long as you don't use
```
new
```
and as long as the derived objectd don't have custom destructors, though, you could be lucky.
/EDIT: On the other hand, if the code is only used as in the question, inheritance has no advantage over composition. Just follow the advice given by m_pGladiator.