[GSoC] Header Generation for C/C++

Eduard Staniloiu edi33416 at gmail.com
Wed Jul 17 12:50:56 UTC 2019


On Wednesday, 17 July 2019 at 11:52:17 UTC, Nicholas Wilson wrote:
> On Wednesday, 17 July 2019 at 11:05:21 UTC, Eduard Staniloiu 
> wrote:
>> On Tuesday, 16 July 2019 at 13:46:56 UTC, rikki cattermole 
>> wrote:
>>> So currently there is no way to restrict it to just extern(C)?
>>> I ask this because -HC makes me think C not C++ headers.
>>
>> Currently the outputted headers are C++ headers, but we were 
>> thinking of wrapping `extern (C++)` definitions inside an 
>> `#ifdef __cplusplus` block, and prefixing any `extern (C)` 
>> definitions with the following `EXTERNC` macro
>>
>> ```
>> #ifdef __cplusplus
>> #define EXTERNC extern(C)
>> #else
>> #define EXTERNC
>> #endif
>> ```
>>
>> This way, the generated header could be used in both C and C++.
>>
>> What do you think?
>
> It should be pretty trivial to just check the linkage of the 
> symbols and only output extern(C) symbols.

This would require two compiler switches, one for C (-HC ?) and 
one for C++ (-HCPP ?).
Was trying to keep it as one compiler switch.

>
> Also you've clearly been doing too much D programming! (which 
> is probably a good thing) That would be:
> #define EXTERNC extern "C" {
>
> and you need to macro the closing brace as well.

Good catch! Thank you


More information about the Digitalmars-d mailing list