Boost logo

Boost :

Subject: [boost] [Style] Import a C function with wrong signature on purpose
From: Klemens Morgenstern (klemens.morgenstern_at_[hidden])
Date: 2016-05-02 13:54:43


Hi,

for the boost.process library I need WinAPI functions which take an
enumerator. Problem is: the forward-declaration doesn't work here, even
with C++11. I.e. this code is still illegal, because X has a non-fixed type:

enum X {};
enum X : typename std::underlying_type<X>::type ;

I do however know which values the enum has take, thus I can redeclare
it and have the reasonable expectation, that it will use the same
underlying type. So theoretically, I could import the function into a
seperate namespace (using extern "C") and use it, while having it
declared with another enum type.

I.e. you have in some C code the declaration:

enum X { a,b,c};
void f(X);

And I'll write in my code without including the other header:

namespace import_thingy {
extern "C" {
enum X { a,b,c};
void f(X);
}

To be absolutely sure, I'd add an test, which asserts that the
underlying types are equal.

Now of course, that would never be accepted into the boost/winapi
module, but I could just add this in my library. Would this be a
dealbreaker for a library attempting to become a boost-library? If so,
I'd need to put it into a source file and include windows.h there, but
I'd really like the library to be header-only and under no circumstances
include windows.h there.

Thanks,

Klemens


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk