>> How about good old C-style reuse? Make your C source file look like so:
>> enum anenum {
[quoted text clipped - 3 lines]
> Would you elaborate a bit on this? I've never met the include keyword in
> such a syntax.
The #include directive will cause the preprocessor to simply replace the
directive with the contents of whatever file it references. So if you
have a file that contains just the "guts" of the enumeration, you can
#include it from within the enum declaration itself.
Example:
file myheader.h:
enum anenum
{
#include "anenum.h"
}
file anenum.h:
Value1,
Value2,
Value3
Then when compiled, the compiler winds up seeing this:
enum anenum
{
Value1,
Value2,
Value3
}
How this addresses your original question is not clear to me. You seem to
be asking how you can effectively import enumerations declared in C, into
a C# program. While you could define the enumeration as suggested, I'm
not aware of any way to do the similar #include in C#, so having the
internal part of the enum declaration in a separate file doesn't seem to
help you.
Maybe Ben can elaborate on his suggestion, especially regarding how he
expects it to be used from the C# side.
Pete
A n g l e r - 20 Jul 2007 09:10 GMT
> How this addresses your original question is not clear to me. You
> seem
[quoted text clipped - 7 lines]
> Maybe Ben can elaborate on his suggestion, especially regarding how he
> expects it to be used from the C# side.
Normally, you would give a go to a managed library compiled with /clr,
so managed C++ project code would be visible to C# (if attached to a C#
based project). The following example explains this a bit (I assume
#include is supported by a managed syntax as well - haven't tried yet).
What I'm wondering is whether I could avoid this and just use
include-like directive in C# or sth likewise so not to create a managed
wrapper just for sake of sharing enums ....
#ifdef _MANAGED
using namespace System;
using namespace System::Runtime::InteropServices;
public ref class MyClass1
{
private:
....
public:
typedef enum class SomethingClass: uchar { #include "anenum.h" };
};
#endif
Ben Voigt [C++ MVP] - 23 Jul 2007 16:50 GMT
>> How this addresses your original question is not clear to me. You seem
>> to be asking how you can effectively import enumerations declared in
[quoted text clipped - 12 lines]
> directive in C# or sth likewise so not to create a managed wrapper just
> for sake of sharing enums ....
That's basically what I intended for you to do, but...
> #ifdef _MANAGED
>
[quoted text clipped - 8 lines]
> public:
> typedef enum class SomethingClass: uchar { #include "anenum.h" };
Preprocessor directives need to appear on their own line, you can't put
#include in the middle of a line.
> };
> #endif