The extern "C" construct - does it allow the use of C-style (int-based) enums?

I am trying to include a header file which was written in C, but my
project is in C++. Even when I wrap the include statement or the
entire header files with extern "C" (used according to the
instructions on c++-faq-lite), I get the same error, which is this:

invalid conversion from `int' to `DmtxDirection'

where DmtxDirection is an enum with integer values inside (obviously).

Advertisements

Re: The extern "C" construct - does it allow the use of C-style (int-based)enums?

Chris Cahoon wrote:
> Hello,
>
> I am trying to include a header file which was written in C, but my
> project is in C++. Even when I wrap the include statement or the
> entire header files with extern "C" (used according to the
> instructions on c++-faq-lite), I get the same error, which is this:
>
> invalid conversion from `int' to `DmtxDirection'
>
> where DmtxDirection is an enum with integer values inside (obviously).

Which will cause a few problems when the header is compiled as
C. If he has access to the header, and can modify it, then
he can use a C style cast here. If he doesn't, he'll need to
"pre-process" the header somehow, and include the pre-processed
version. (If he's using make, it's almost trivial to get the
system to invoke the preprocessing automatically. If he's using
an IDE, I don't know.)

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!