atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
231 stars 31 forks source link

#pragma once #106

Closed Laeeth closed 5 years ago

Laeeth commented 5 years ago

Not implementing this leads to errors when headers are included multiple times. Example is a bit convoluted. aerospike/as_record.h

atilaneves commented 5 years ago

Implement it how?

When headers are included in a .dpp file, whatever translation unit is seen by clang is what what gets translated - there's nothing to implement since it's a #pragma to clang itself.

On the D side, importing a module twice is fine, but #including a header in two .dpp files is not recommended.

Without an example of what doesn't work and what was expected there's not much I can do.

Laeeth commented 5 years ago

Did you try the examples?

Laeeth commented 5 years ago

Singular

atilaneves commented 5 years ago

I'll try as_record.h from aerospike once I set up an Ubuntu box I can install the .deb to. I'm wondering what it could be - maybe that libclang, as opposed to the actual compiler, needs a command-line switch to enable #pragma once.

Laeeth commented 5 years ago

You can just clone the repo source code. You don't need to actually run it and if you do then from source is fine also.

My guess is that problem might have gone away after I fixed forward declarations as I didn't see anything similar with Xenon so far.

I assumed the problem was pragma once because I didn't have time to look into it properly. But there was definitely a problem with multiple declarations.

Yes thinking about it the forward declaration fix does more than that. If you end up with a function or aggregate definition more than once it doesn't matter - only the proper aggregate definition and only one function prototype will be used. The former definitely and I think latter but didn't check yet.

Laeeth commented 5 years ago

https://github.com/aerospike/aerospike-client-c

atilaneves commented 5 years ago

This worked fine:

./d++ --include-path aerospike-client-c/src/include --include-path aerospike-client-c/modules/common/src/include aerospike.dpp 
// aerospike.dpp
#include "aerospike/as_record.h"

void main() {
    auto rec = as_record();
    rec.gen = 42;
}