[GSoC] Header Generation for C/C++

Eduard Staniloiu edi33416 at gmail.com
Wed Jul 17 11:36:52 UTC 2019


On Wednesday, 17 July 2019 at 04:43:52 UTC, Manu wrote:
> On Tue, Jul 16, 2019 at 9:40 PM Nicholas Wilson via 
> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>
>> On Wednesday, 17 July 2019 at 04:05:57 UTC, Manu wrote:
>> > One hopefully trivial request, I wouldn't want the compiler 
>> > to emit a single header; I would want it to emit one .h per 
>> > .d file into the output directory.
>>
>> Forward declarations make that a PITA.
>
> Hmmm...

I'm glad to hear that you are excited and eager to give it a spin 
:D

As Nicholas pointed out, forward declarations make it a pain.
Say you have the following example modules, `a.d` and `b.d`
```
// a.d
module a;

import b;

extern (C++) struct A
{
   TestEnum e;
}

// b.d
module b;

enum TestEnum
{
   aa,
   bb
}
```

For `a.d` you'll get
```
// a.h
#pragma once

enum TestEnum
{
     TESTENUMaa = 0,
     TESTENUMbb = 1
};

struct A
{
     TestEnum e;
};
```

For `b.d` you'll get
```
// b.h
#pragma once

enum TestEnum
{
     TESTENUMaa = 0,
     TESTENUMbb = 1
};
```

When you'll bring the two headers together, you'll get a 
re-definition error for the enum.

One way to go with this would be to have wrap the definitions 
inside an `#ifndef \ #define` block.

Another one would be to check from which module does the forward 
declaration come from and replace that with an `#include "b.h"`, 
but I don't know how complicated this would be, as not all 
forward declarations come from a different module.


More information about the Digitalmars-d mailing list