Re: Memory layout changed for classes with virtual functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 27 December 2010 13:16, ronny meeus wrote:
> On Sun, Dec 26, 2010 at 5:21 PM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:
>>
>> You could put the next pointer in a separate struct which has no
>> virtual functions, so it has the same layout in C and C++, then use
>> that as a base class for a polymorphic C++ type.  The C code
>> manipulating the next pointer would only deal with the portable type.
>
> I understand this. The problem with this approach is that you force
> your user to introduced an inheritance relationship with the
> baseclass. If this needs to be introduced in an existing class
> hierarchy it can introduce certain complexities.

The code already has horrible, non-portable complexities.

You have the option of replacing them with portable complexity.

>> Or you could create an interface for manipulating the linked lists,
>> compile the implementation as C++, and always modify the lists through
>> that interface.
>
> I do not understand what you mean with an interface.
> In Java we have interfaces but as far as I know, this concept does not
> exists in C++.
> If you mean just a class with abstract interfaces, I do not see what
> the difference is with the base class approach mentioned above.

I don't mean the Java keyword 'interface' I just mean an API which
hides the implementation
http://en.wikipedia.org/wiki/Interface_(computer_science)

You could, for instance, declare functions to manipulate the pointers,
and call those functions to add an a element to the linked list,
instead of fiddling with raw memory everytime you want to manipulate a
list.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux