[Development] Fornux C++ Superset

Phil Bouchard philippeb8 at gmail.com
Tue May 1 01:17:49 CEST 2018


On 04/25/2018 08:02 AM, Phil Bouchard wrote:
> Support for nested structures is easy to fix and will just take a day or 
> two to do so. For example:
> 
> struct A
> {
>    struct B
>    {
>    };
> };
> 
> Will be converted into the following so that I can have their 
> specialization in a top-level namespace:
> 
> struct A__B
> {
> };
> 
> struct A
> {
> };
> 
> Since there is no hidden catch then I will tell you right now that:
> - NULL C pointers will need to be typed
> - pointer casts to their encompassing structure needs to use 
> _containerof() macro
> - C-style array parameters needs to be converted to pointers
> - Types instantiated in the same statement need not be different (Ex.: 
> int * i, j[4]; // needs to be 2 different statements)
> 
> That's about it. It took me 1 week to adapt "libarchive" to follow the 
> aforementioned rules:
> https://github.com/philippeb8/libarchive/commit/5858b5c047301123ffdf05f247f7d191829d5a9b 

I just tried to support nested structures and given nested structures 
and template specializations aren't commutative then it's not possible 
to support them if you want to respect the access scope at the same 
time. If you give up the nested declaration and therefore the access 
scope privileges then it'll be fine. Ex:

struct A
{
     static int i;

     struct B
     {
     } b; // can access i
};

// Would be converted to:

struct A__B
{
};

struct A
{
     static int i;

     A__B b; // cannot access i
};

The day the C++ language will support nested forward declarations 
correctly then it'll be possible but not for now. Ex.:

struct A::B::C;

Honestly it took me 1 week to patch libarchive and Fornux C++ Superset 
was able to fix the leaks they were living with for the last 3 years.


Regards,
-Phil




More information about the Development mailing list