From: William S F. <ws...@fu...> - 2009-08-30 01:13:20
|
Santosh Joseph wrote: > hi, > I have declared "%csconst(1);" > but I'm having problems with code that does not compile. > for example: in my header file: > #define ID_INVALID 0xFFFFFFFF > translates to: > public const int ID_INVALID = 0xFFFFFFFF; > this doesn't compile because it can't convert int to uint (without a cast). > what i want to know is if i can declare the constant to be of type uint instead of int. > i think i can use the %constant statement in the swig input file to get around this, > but i have many #defines like above and i don't want the maintenance (i'm just inputting > my header file directly to swig). > any suggestions? i also used a typemap (from php's const.i), but that didn't work either. > thanks for any help. The caveat as documented is that %csconst(1) does not always work, as valid C does not necessarily compile as C#, note that 'int f = 0xFFFFFFFF;' is perfectly valid in C. You can work around this using a typemap: %typemap(cstype) int ID_INVALID "uint" #define ID_INVALID 0xFFFFFFFF Note that the typemap type is int, as that is the inferred type that SWIG uses. If you define it as unsigned type, eg: #define ID_INVALID 0xFFFFFFFFu then SWIG will know that it is unsigned and use uint in C#. William |