<ca***********@yahoo.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
>I am converting a couple of C header files to C#. It is mainly just a
bunch C structs but I am not sure how to handle the #ifdef and #ifndef
in C#. For example:
#ifndef DATE_TIME
#define DATE_TIME unsigned long
#endif // NOT DATE_TIME
The #define DATE_TIME I am handling with:
public const UInt32 DATE_TIME;
That's not the same thing. The C code declares a type alias, and you just
defined a single const variable instance.
What should be the rigfht approach to convert this type of C code?
Well you have two choices.
Either retain the C type alias. In C# the 'using' directive can create a
type alias for a single file. At the top of the file add:
using DATE_TIME = System.Int32;
Or just replace all occurances of DATE_TIME with the corresponding CLR type,
Int32.
Which to use? If you're hoping to retain the flow and "flavor" of the C
code, use the type alias. For instance if you are interoperating with a DLL
that uses these types, the type alias is appropriate.
If you are doing a more substantial rewrite, you should get rid of the type
alias because in normal C# usage they are very rarely used.
David