If you have a macro like this in C:
#define SLICE_VERSION 20110614
How to use this macro in C# Script?
Should I marshal it? How?
Should I re-define it in C#? I know C# does not have #define macro but maybe I can just define it as a static variable.
Or can I refer to it somehow?
Similarly, if you have a global variable in C, how do you use it in C# script?
I have seen tutorials about marshaling classes, structures, arrays, unions and lots of other things from C/C++ to C#, but I haven’t been able to find any hint about how marshal a constant… Or do I have to marshal it? Can it be referred to directly?
BTW, I found this a pretty good tutorial about interopping on Mono: http://www.mono-project.com/Interop_with_Native_Libraries#Introduction
Yes. In C#, you’d want to use a
const:That being said, I’ll often rename this to make it more C#-standard, as well:
Depending on how it’s being used, you make wish to specify an access modifier explicitly, as well. Also, depending on the usage, you may want to use a different type (Int32 may not be correct – you may want UInt32, etc.). One disadvantage to macros in C/C++ is that they are not strongly typed, so without seeing the usage, there is no way to know the exact type expected here.